# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
860782 | vjudge1 | Prisoner Challenge (IOI22_prison) | 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;
set<int> S;
int ask(int y){
cout<<"? "<<y<<endl;
cout.flush();
int x;
cin>>x;
if(x==-1) return -1;
S.insert(x^y);
return x^y;
}
int tree(int pot, int m, int minimo, int maximo){
if((maximo==minimo)|(pot==1)){
return 0;
}else if(maximo<m+(pot/2)){
return tree(pot/2, m, minimo, maximo);
}else if(minimo>=m+(pot/2)){
return tree(pot/2, pot/2+m, minimo, maximo);
}else{
int M = ask(m+pot/2-1);
if(M==-1) return -1;
int s=0;
if((M!=minimo)&(M!=maximo)){
s=tree(pot/2, m, minimo, M);
}
if(s==-1) return -1;
M = ask(m+pot/2);
if(M==-1) return -1;
s=0;
if((M!=minimo)&(M!=maximo)){
s=tree(pot/2, m+pot/2, M, maximo);
}
if(s==-1) return -1;
}
return 0;
}
int main(){
int T=1;
for(int dalekofrivia=T; dalekofrivia>0; dalekofrivia--){
int n;
cin>>n;
int pot=1;
while(pot<1000000000){
pot*=2;
}
int l = ask(0);
int r = ask(pot-1);
if(tree(pot, 0, l, r)==0){
cout<<"!";
for(int x: S) cout<<" "<<x;
cout<<endl;
}
}
return 0;
}