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>
#define vec vector
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
using namespace std;
const int N=1e2;
int f;
void debug(vec<int> vc){
cout<<"DEBUG"<<endl;
for(auto &z : vc) cout<<z<<' ';
cout<<endl;
}
vec<int> del(vec<int> &a,vec<int> &b,int w){
map<int,int>mp;
vec<int>c;
for(auto &z : b) mp[z]--;
for(auto &z : a) mp[z]++;
// debug(a);
// debug(b);
if(w)mp[0]--;
for(auto &z : mp){
int x=z.s/((w?2:1));
while(x--){
if(w) c.pb(z.f^f);
else c.pb(z.f);
}
}
sort(c.begin(),c.end());
return c;
}
vec<int> get(vec<int> inds){
if(!sz(inds)) return vec<int>();
for(auto &z : inds) z+=2;
map<int,int>mp;
vec<int>a=inds,b=inds,c;
b.pb(1);
a=get_pairwise_xor(a),b=get_pairwise_xor(b);
return del(b,a,1);
}
vec<int>have[7],nothave[7];
void era(vec<int> &a,int x){
int j=-1;
for(int i=0;i<sz(a);i++){
if(x==a[i])j=i;
}
assert(j!=-1);
a.erase(a.begin()+j,a.begin()+j+1);
}
vec<int>all;
int m;
int answ[N];
void rec(int st){
if(st>=7)return;
vec<int>vc;
for(int i=0;i<=m;i++){
if((1<<st)&i) vc.pb(i);
}
// if(st==3){
// st=3;
// }
// cerr<<st<<endl;
have[st]=get(vc);
// assert(sz(vc)==sz(have[st]));
// cerr<<"ST "<<' '<<st<<endl;
// assert(have[st]);
nothave[st]=del(all,have[st],0);
rec(st+1);
}
vector<int> guess(int n) {
vector <int> ans;
m=n;
m-=2;
f=ask(1);
vec<int>p(m+1);iota(p.begin(),p.end(),0);
all=get(p);
rec(0);
for(int i=0;i<=m;i++){
map<int,int>mp;
for(int st=0;st<7;st++){
if((1<<st)&i){
for(auto &z : have[st]){
if(mp[z]==st) mp[z]++;
}
}
else{
for(auto &z : nothave[st]){
if(mp[z]==st) mp[z]++;
}
}
}
for(auto &z : mp){
if(z.s==7){
///it will be good
int x=z.f;
answ[i]=x;
for(int st=0;st<7;st++){
if((1<<st)&i){
era(have[st],x);
}
else{
era(nothave[st],x);
}
}
// cout<<x<<' ';
// break;
}
}
}
m+=2;
ans.pb(f);
for(int i=0;i<m-1;i++){
ans.pb(answ[i]);
}
return ans;
}
/*
13
12 99 65 42 6 27 100 45 57 1 34 6 9
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |