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 <interactive.h>
#include <bits/stdc++.h>
using namespace std;
/*vector<int> unk;
int ask(int i) {
return unk[i - 1];
}
vector<int> get_pairwise_xor(vector<int> a) {
vector<int> res;
for (const int& i : a) {
for (const int& j : a) {
res.emplace_back(unk[i - 1] ^ unk[j - 1]);
}
}
sort(res.begin(), res.end());
return res;
}
*/
vector<int> guess(int n) {
vector<int> toAsk, x1, x2, ans(n);
ans[0] = ask(1);
unordered_map<int, int> idxOf;
for (int bit = 31 - __builtin_clz(n) - (__builtin_popcount(n) == 1); bit >= 0; --bit) {
toAsk.clear();
for (int i = 1; i < n; ++i) {
if ((i & (1 << bit)) != 0) {
toAsk.emplace_back(i + 1);
}
}
x1 = get_pairwise_xor(toAsk);
toAsk.emplace_back(1);
x2 = get_pairwise_xor(toAsk);
int ptr1 = (int)toAsk.size() - 1, ptr2 = (int)toAsk.size();
while (ptr2 < (int)x2.size()) {
if (ptr1 < (int)x1.size()) {
if (x1[ptr1] == x2[ptr2]) {
ptr1 += 2, ptr2 += 2;
} else if (x1[ptr1] < x2[ptr2]) {
ptr1 += 2;
} else {
idxOf[x2[ptr2] ^ ans[0]] ^= (1 << bit);
ptr2 += 2;
}
} else {
idxOf[x2[ptr2] ^ ans[0]] ^= (1 << bit);
ptr2 += 2;
}
}
}
for (const auto& [num, idx] : idxOf) {
ans[idx] = num;
}
return ans;
}
/*
void solve() {
int n;
cin >> n;
unk.resize(n);
for (int i = 0; i < n; ++i) {
cin >> unk[i];
}
unk = guess(n);
for (const int& x : unk) {
cout << x << ' ';
}
cout << endl;
}
int main() {
// ios_base::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
solve();
}
return 0;
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |