QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#712102 | #8239. Mysterious Tree | KafuuChinocpp# | WA | 1ms | 3900kb | C++14 | 1.3kb | 2024-11-05 14:34:01 | 2024-11-05 14:34:48 |
Judging History
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), fflush(stdout);
else printf("? %d %d\n",i,i-1), fflush(stdout);
int ans;
cin>>ans;
if(ans){
int res[2]={0}, cnt=-1;
for(int j=1;j<=n;j++){
if((i!=n&&j!=i&&j!=i+1)||(i==n&&j!=i&&j!=i-1)){
printf("? %d %d\n",i,j); fflush(stdout);
cin>>res[++cnt];
if(cnt==0&&!res[cnt]) break;
}
if(cnt==1){
if(res[0]&&res[1]) printf("! 2\n"), fflush(stdout);
else printf("! 1\n"), fflush(stdout);
flag=1;
break;
}
}
if(flag) break;
res[0]=res[1]=0; cnt=-1;
for(int j=1;j<=n;j++){
if(i!=n&&j!=i&&j!=i+1){
printf("? %d %d\n",i+1,j); fflush(stdout);
cin>>res[++cnt];
}
else if(i==n&&j!=i&&j!=i-1){
printf("? %d %d\n",i-1,j); fflush(stdout);
cin>>res[++cnt];
}
if(cnt==1){
if(res[0]&&res[1]) printf("! 2\n"), fflush(stdout);
else printf("! 1\n"), fflush(stdout);
flag=1;
break;
}
}
}
}
if(!flag) printf("! 1\n"), fflush(stdout);
}
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: 100
Accepted
time: 1ms
memory: 3900kb
input:
2 4 1 0 1 0 4 1 1 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 3 4 ? 3 1 ? 3 2 ! 2 ? 1 0
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3840kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 1 1 1 7
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 12 1 ? 12 2 ! 2 ? 13 12 ? 13 1 ? 13 2 ! 2 ? 1 0 ! 1
result:
wrong answer Integer 0 violates the range [1, 7] (test case 3)