Official analysis: https://code.google.com/codejam/contest/2437488/dashboard#s=a
C++ codes
Problem A (small)
#include <fstream>
#include <string>
#include <cctype>
using namespace std;
inline bool is_constant(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c =='u')
return false;
return true;
}
int main() {
ifstream fin("A-small-attempt0.in");
ofstream fout("A-small-attempt0.out");
int T;
fin >> T;
for (int casenum = 1; casenum <= T; ++casenum) {
int ans = 0, n;
string str;
fin >> str >> n;
int len = str.length();
for (int i = 0; i < len; ++i)
for (int j = i + n - 1; j < len; ++j) {
int cnt = 0;
for (int k = i; k <= j; ++k)
if (is_constant(str[k])) {
++cnt;
if (cnt >= n) {
++ans;
break;
}
} else {
cnt = 0;
}
}
fout << "Case #" << casenum << ": " << ans <<'\n';
}
fin.close();
fout.close();
//system("pause");
return 0;
}
#include <fstream>
#include <string>
#include <cctype>
#include <cstdio>
using namespace std;
inline bool is_constant(char c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c =='u')
return false;
return true;
}
int main() {
ifstream fin("A-small-attempt0.in");
//ofstream fout("A-large.out");
FILE *fout = fopen("A-small-attempt0.out", "w");
int T;
fin >> T;
for (int casenum = 1; casenum <= T; ++casenum) {
double ans = 0;
int n;
string str;
fin >> str >> n;
int num = 0, cnt = 0;
int len = str.length();
bool consec = false;
int start;
for (int i = 0; i < len; ++i) {
if (is_constant(str[i])) {
++cnt;
if (cnt >= n) {
consec = true;
start = i - n + 1;
}
} else {
cnt = 0;
}
if (consec)
ans += (start + 1);
}
//fout << "Case #" << casenum << ": " << ans <<'\n';
fprintf(fout, "Case #%d: %.0lf\n", casenum, ans);
}
fin.close();
//fout.close();
//system("pause");
return 0;
}
Problem B (small)
#include <fstream>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
ifstream fin("B-small-attempt1.in");
ofstream fout("B-small-attempt1.out");
int T;
fin >> T;
for (int casenum = 1; casenum <= T; ++casenum) {
int X, Y;
fin >> X >> Y;
string ans = "";
string tmp;
if (X < 0) tmp = "EW";
else tmp = "WE";
for (int i = 0; i < abs(X); ++i)
ans += tmp;
if (Y < 0) tmp = "NS";
else tmp = "SN";
for (int i = 0; i < abs(Y); ++i)
ans += tmp;
fout << "Case #" << casenum << ": " << ans << '\n';
}
fin.close();
fout.close();
return 0;
}
Problem C (small)
#include <fstream>
#include <queue>
#include <functional>
using namespace std;
int main() {
ifstream fin("C-small-attempt0.in");
ofstream fout("C-small-attempt0.out");
int T;
fin >> T;
for (int casenum = 1; casenum <= T; ++casenum) {
const int MAXN = 10;
int N, d[MAXN], n[MAXN], w[MAXN], e[MAXN], s[MAXN], delta_d[MAXN], delta_p[MAXN], delta_s[MAXN];
fin >> N;
for (int i = 0; i < N; ++i)
fin >> d[i] >> n[i] >> w[i] >> e[i] >> s[i] >> delta_d[i] >> delta_p[i] >> delta_s[i];
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for (int i = 0; i < N; ++i)
for (int j = 0; j < n[i]; ++j)
q.push(make_pair(d[i] + j * delta_d[i], i));
int ans = 0;
const int ORIGIN = 300;
vector<int> wall(2 * ORIGIN, 0);
vector<int> new_wall = wall;
while (!q.empty()) {
int day = q.top().first, t = q.top().second;
q.pop();
bool commit = true;
if (!q.empty() && q.top().first == day) commit = false;
int idx = (day - d[t]) / delta_d[t];
int west = w[t] + idx * delta_p[t] + ORIGIN;
int east = e[t] + idx * delta_p[t] + ORIGIN;
int strength = s[t] + idx * delta_s[t];
bool success = false;
for (int i = west; i < east; ++i)
if (wall[i] < strength) {
success = true;
if (new_wall[i] < strength)
new_wall[i] = strength;
}
if (success) ++ans;
if (commit) wall = new_wall;
}
fout << "Case #" << casenum << ": " << ans << '\n';
}
fin.close();
fout.close();
return 0;
}