// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
#include "interactive.h"
using namespace std;
#define nl '\n'
#define pb push_back
template<class T> using V = vector<T>;
V<int> sub(V<int> A, V<int> B){
V<int> C;
for(auto& x : A) if (find(begin(B), end(B), x) == end(B)) C.push_back(x);
return C;
}
V<int> add(V<int> A, V<int> B){
V<int> C = B;
for(auto& x : A) if (find(begin(C), end(C), x) == end(C)) C.push_back(x);
return C;
}
const int LG = 7;
V<int> guess(int N) {
V<int> ans(N);
// auto PRINT = [&](V<int> X) {
// cout << "ARRAY: ";
// for(auto x : X) cout << x << " ";
// cout << endl;
// };
auto XOR = [&](int x, bool IN) {
V<int> idx; for(int i = 0; i < N; i++) if ((i >> x) & 1) idx.pb(i + 1);
if (IN) idx.pb(1);
if (size(idx) <= 1) return V<int>();
// cout << x << " " << IN << endl;
// PRINT(idx);
V<int> K = get_pairwise_xor(idx);
// cout << "K: ";
// PRINT(K);
// cout << endl;
map<int, int> C; for(auto& v : K) C[v]++;
V<int> RES; for(auto p : C) if (p.first != 0) {
for(int t = 0; t < p.second / 2; t++) RES.push_back(p.first);
}
// cout << "RES: ";
// PRINT(RES);
// cout << endl;
return RES;
};
auto ASK = [&](int x) { return ask(x + 1); };
V<V<int>> R(LG), L(LG), D(LG);
V<int> ALL;
for(int b = 0; b < LG; b++) {
R[b] = sub(XOR(b, 1), XOR(b, 0));
// cout << "R[b]: ";
// PRINT(R[b]);
// cout << endl;
}
for(int b = LG - 1; b >= 1; b--) {
D[b] = add(R[b], L[b]);
// cout << "D[b]: ";
// PRINT(D[b]);
// cout << endl;
L[b - 1] = sub(D[b], R[b - 1]);
// cout << "L[b - 1]: ";
// PRINT(L[b - 1]);
// cout << endl;
}
ALL = add(L[0], R[0]);
ans[0] = ASK(0);
for(auto& x : ALL) {
int pos = 0;
// cout << x << endl;
for(int i = 0; i < LG; i++) if (find(begin(R[i]), end(R[i]), x) != end(R[i])) {
pos ^= (1 << i);
}
// cout << pos << " " << (x ^ ans[0]) << endl << endl;
ans[pos] = x ^ ans[0];
}
// cout << "DONE" << endl;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
336 KB |
Output is correct |
2 |
Correct |
4 ms |
336 KB |
Output is correct |
3 |
Incorrect |
3 ms |
336 KB |
Output is not correct |
4 |
Halted |
0 ms |
0 KB |
- |