QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#364246 | #8239. Mysterious Tree | ucup-team1525# | WA | 1ms | 3964kb | C++17 | 1.3kb | 2024-03-24 13:12:58 | 2024-03-24 13:12:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1e3;
int n;
int a[N+5];
int u,v;
int query(int x,int y){
printf("? %d %d\n",x,y);
fflush(stdout);
int tp;
scanf("%d",&tp);
return tp;
}
void solve(){
scanf("%d",&n);
u=v=-1;
for(int i=1;i<=n;i+=2)
if(query(i,i+1)){
u=i; v=i+1;
}
if(n&1){
if(query(n,n-1)){
u=n; v=n-1;
}
}
if(u==-1&&v==-1){
printf("! 2\n");
return;
}
for(int i=1;i<=n;i++)
if(i!=u&&i!=v){
bool ok=0;
if(query(u,i))
ok=1;
else if(query(v,i)){
swap(u,v); ok=1;
}
if(!ok){
puts("! 1");
return;
}
for(int j=i+1;j<=n;j++)
if(j!=u&&j!=v)
if(query(u,j)){
printf("! 2\n");
return;
}
else{
printf("! 1\n");
return;
}
}
}
int main(){
int t; scanf("%d",&t);
while(t--){
solve();
fflush(stdout);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3964kb
input:
2 4 1 1 0 0 4 0 1 1 1
output:
? 1 2 ? 3 4 ? 3 1 ? 4 1 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 3 2 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3908kb
input:
87 13 0 0 0 0 0 1
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14
result:
wrong answer Integer 14 violates the range [1, 13] (test case 1)