이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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){
unordered_map<int, int> C;
for(auto& v : A) C[v]++;
for(auto& v : B) C[v]--;
V<int> RES;
for(auto p : C) for(int t = 0; t < p.second; t++) RES.push_back(p.first);
return RES;
}
V<int> add(V<int> A, V<int> B){
unordered_map<int, int> C;
for(auto& v : A) C[v]++;
for(auto& v : B) C[v]++;
V<int> RES;
for(auto p : C) for(int t = 0; t < p.second; t++) RES.push_back(p.first);
return RES;
}
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;
unordered_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 << b << " ";
// 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |