# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
860782 | vjudge1 | 죄수들의 도전 (IOI22_prison) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}