Hi! I'm not very experienced at interactive problems. Below is the code for
Codejam's 4th problem "ESAb ATAd". It passes the test set 1 but give *RE*
for Test set 2. Can anyone please point out what is causing the Runtime
error here?
#include<bits/stdc++.h>
using namespace std;
vector<int> parity, value;
int t, b, qry, sp, dp;
int read (int i) { int in; cout << i+1 << endl; qry++; cin >> in; return in
;}
void update (int p, int z, int n) {
if (value[z]^read(z) == 0)
return;
for (int i = 0; i < n; i++) {
if (parity[i] == p)
value[i] = 1-value[i], value[b-1-i] = 1-value[b-1-i];
}
}
int main() {
cin >> t >> b;
value.resize(b, 0);
parity.resize(b/2, 0);
for (int tc = 1; tc <= t; tc++) {
qry = 0, sp = dp = -1;
for (int i = 0, j ; i < b/2; i++) {
if (qry%10 == 0) {
if (sp != -1) update (1, sp, i);
if (dp != -1) update (0, dp, i);
}
j = b-1-i;
value[i] = read(i), value[j] = read(j);
if (value[i] == value[j]) parity[i] = 1, sp = i;
else dp = i;
}
string bits = "";
for (int ch: value) bits += ch+'0';
cout << bits << endl;
char judge; cin >> judge;
assert(judge == 'Y');
}
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/f76827ed-97a7-40bd-9cf7-a9123936bccf%40googlegroups.com.