QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712008 | #8239. Mysterious Tree | KafuuChinocpp# | TL | 0ms | 0kb | C++14 | 944b | 2024-11-05 14:16:20 | 2024-11-05 14:16:22 |
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3e5+10;
int T,n;
void solve(){
cin>>n;
int flag=0;
for(int i=1;i<=n;i+=2){
if(i!=n) printf("? %d %d\n",i,i+1);
else printf("? %d %d\n",i,i-1);
int ans;
cin>>ans;
if(ans){
if(i!=n){
int res[2]={0}, cnt=0;
for(int j=1;j<=n;j++){
if(j!=i&&j!=i+1){
printf("? %d %d\n",i,j);
cin>>res[cnt++];
}
if(cnt==2){
if(res[0]&&res[1]) printf("! 2\n");
else printf("! 1\n");
flag=1;
break;
}
}
}
else{
int res[2]={0};
printf("? %d 1\n",n); cin>>res[0];
printf("? %d 2\n",n); cin>>res[1];
if(res[0]&&res[1]) printf("! 2\n");
else printf("! 1\n");
flag=1;
break;
}
break;
}
}
if(!flag) printf("! 1\n");
}
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin>>T;
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 4