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;
template<typename T>
using vec = vector<T>;
#define bit(x, i) ((x >> i) & 1)
vector<int> guess(int n) {
vector<int> ans(n);
ans[0] = ask(1);
map<int, int> ans_map;
ans_map[ans[0]] = 0;
for (int b = 10; b >= 0; b--) {
vec<int> ids;
for (int i = 1; i < n; i++)
if (bit(i, b)) ids.push_back(i + 1);
if (ids.empty()) continue;
auto xors1 = get_pairwise_xor(ids);
ids.push_back(1);
auto xors2 = get_pairwise_xor(ids);
// find diff
multiset<int> xors1_ms(xors1.begin(), xors1.end());
vec<int> diff;
for (int i: xors2) {
if (xors1_ms.count(i) == 0) {
diff.push_back(i);
} else {
xors1_ms.erase(xors1_ms.find(i));
}
}
sort(diff.begin(), diff.end());
// unique(diff.begin(), diff.end());
diff.erase(unique(diff.begin(), diff.end()), diff.end());
for (int i = 1; i < diff.size(); i++) {
int vl = diff[i] ^ ans[0];
if (ans_map.count(vl) == 0) {
ans_map[vl] = 0;
}
ans_map[vl] += 1 << b;
}
}
for (auto &p: ans_map) {
ans[p.second] = p.first;
}
return ans;
}
Compilation message (stderr)
Xoractive.cpp: In function 'std::vector<int> guess(int)':
Xoractive.cpp:36:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int i = 1; i < diff.size(); i++) {
| ~~^~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |