# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
519225 | Ai7081 | Xoractive (IZhO19_xoractive) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
//int ask(int i);
//vector<int> get_pairwise_xor(vector<int> pos);
vector<int> guess(int n) {
vector<int> ret(n);
ret[0] = ask(1);
vector<int> q;
vector<vector<int>> bit(7);
for (int i=0; i<7; i++) {
q.clear();
for (int j=1; j<=n; j++) {
if ((j>>i)%2 && j>1) q.push_back(j);
}
if (q.empty()) continue;
vector<int> res1, res2;
res1 = get_pairwise_xor(q);
q.push_back(1);
res2 = get_pairwise_xor(q);
int ii=0, jj=0;
while (ii<res1.size() && jj<res2.size()) {
if (res1[ii] > res2[jj]) {
bit[i].push_back(res2[jj]);
jj++;
}
else if (res1[ii] == res2[jj]) {
mark[jj] = true;
ii++;
jj++;
}
}
for (int j=0; j<bit[i].size(); j++) bit[i][j] = (bit[i][j] ^ ret[0]);
}
vector<pair<int, int>> v;
for (int i=0; i<7; i++) {
for (auto x : bit[i]) {
bool ok = false;
for (int j=0; j<v.size(); j++) {
if (x == v[j].first) {
v[j].second += (1<<i);
ok = true;
break;
}
}
if (!ok) {
v.push_back({x, (1<<i)});
}
}
}
for (auto [x, idx] : v) ret[idx-1] = x;
return ret;
}