QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623829 | #8239. Mysterious Tree | bessie_goes_moo# | RE | 0ms | 0kb | C++17 | 1.5kb | 2024-10-09 14:08:12 | 2024-10-09 14:08:14 |
answer
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;
int read(){
int red=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){ if(ch=='-') f=-f;ch=getchar();}
while(ch>='0'&&ch<='9') red=red*10+ch-48,ch=getchar();
return red*f;
}
const int N=1e5+5;
typedef long long LL;
typedef pair<int,int> PII;
int T,n;
map<PII,bool>H;
bool star;
bool Query(int x,int y){
if(x>y) swap(x,y);
if(H.count(mp(x,y))) return H[mp(x,y)];
printf("? %d %d\n",x,y);fflush(stdout);
int z;scanf("%d",&z);
H[mp(x,y)]=z;
}
bool Work(int x){
int y;
if(n-x+1==x) y=1;
else y=n-x+1;
if(Query(x,y)){
for(int k=1;k<=n;k++) if(k!=x&&k!=y){
if(Query(x,k)){
for(int kk=k+1;kk<=n;kk++) if(kk!=x&&kk!=y){
if(Query(x,kk)){star=1;return 1;}
break;
}
star=0;return 1;
}else if(Query(y,k)){
for(int kk=k+1;kk<=n;kk++) if(kk!=x&&kk!=y){
if(Query(y,kk)){star=1;return 1;}
break;
}
star=0;return 1;
}
star=0;return 1;
}
}else return 0;
}
int main(){
// freopen("J.in","r",stdin);
// freopen("J.out","w",stdout);
scanf("%d",&T);
while(T--){
scanf("%d",&n);
star=0;H.clear();
for(int i=n;i>=n/2;i--) if(Work(i)) break;
if(!star) printf("! 1\n");
else printf("! 2\n");
fflush(stdout);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
2 4 0
output:
? 1 4