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;
typedef vector<int> vi;
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ins insert
#define sz(x) (int)(x).size()
int n;
int val;
vi subqs[10];
vi res[10];
vi querySub(vi sub){
if(sz(sub) == 0) return sub;
for(auto &u: sub){
u++;
}
// cout << "sub: ";
// for(auto u: sub){
// cout << u << " ";
// }
// cout << "\n";
vi vals;
map<int, int> freq;
vi q1 = get_pairwise_xor(sub);
// cout << "q1: ";
// for(auto u: q1){
// cout << u << " ";
// }
// cout << "\n";
sub.pb(n);
vi q2 = get_pairwise_xor(sub);
// cout << "q2: ";
// for(auto u: q2){
// cout << u << " ";
// }
// cout << "\n";
for(auto u: q2){
freq[u]++;
}
for(auto u: q1){
freq[u]--;
}
freq[0]--;
for(auto u: freq){
assert(u.s == 0 || u.s == 2);
if(u.s == 2){
vals.pb(u.f^val);
}
}
// cout << "vals: ";
// for(auto u: vals) cout << u << " ";
// cout << "\n";
return vals;
}
void assignQ(int L = 0, int R = 127, int ind = 0){
int M = (L+R)/2;
for(int i = L; i <= M; i++){
if(0 <= i && i <= n-2){
subqs[ind].pb(i);
}
}
if(L == M) return;
assignQ(L, M, ind+1);
assignQ(M+1, R, ind+1);
}
int getPos(int v, int L = 0, int R = 127, int ind = 0){
if(L == R) return L;
int M = (L+R)/2;
bool found = 0;
for(auto u: res[ind]){
if(v == u) found = 1;
}
if(found){
return getPos(v, L, M, ind+1);
}
return getPos(v, M+1, R, ind+1);
}
vi guess(int _n) {
n = _n;
vi ans(n, 0);
val = ask(n);
ans[n-1] = val;
assignQ();
for(int i = 0; i < 10; i++){
if(sz(subqs[i]) == 0) break;
res[i] = querySub(subqs[i]); //what numbers are in this subset?
}
set<int> allvals;
for(int i = 0; i < 10; i++){
for(auto u: res[i]){
allvals.ins(u);
}
}
// cout << "allvals: ";
// for(auto u: allvals) cout << u << " ";
// cout << "\n";
for(auto u: allvals){
ans[getPos(u)] = u;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |