QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395408 | #8239. Mysterious Tree | Qian# | TL | 0ms | 0kb | C++14 | 855b | 2024-04-21 14:16:23 | 2024-04-21 14:16:24 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
int n;
bool ask(int x,int y){
printf("? %d %d\n",x+1,y+1);
fflush(stdout);
int p;
scanf("%d",&p);
fflush(stdout);
return p;
}
int main(){
int T;scanf("%d",&T);
while(T--){
int n;scanf("%d",&n);
fflush(stdout);
bool flag=0;
for(int i=0;i<n;i+=2)
if(ask(i,i+1)){
flag=1;
if(ask(i,(i+2)%n)){
if(ask(i,(i+3)%n)){
printf("! 2\n");
}
else printf("! 1\n");
}
else if(ask(i+1,(i+2)%n)){
if(ask(i+1,(i+3)%n)){
printf("! 2\n");
}
else printf("! 1\n");
}
else printf("! 1\n");
break;
}
if(flag)continue;
if(n&1){
if(ask(n,1)){
if(ask(n,2)){
printf("! 2\n");
}
else printf("! 1\n");
}
else printf("! 1\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 4 1 0 1 0
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4