QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#560211 | #8239. Mysterious Tree | shabi666# | WA | 1ms | 3632kb | C++14 | 3.1kb | 2024-09-12 14:20:38 | 2024-09-12 14:20:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
int a[N];
int n,m;
void solve(){
cin>>n;
if(n%2)
{
int flag=1;
for(int i=1;i<n;i+=2)
{
cout<<"? "<<i<<' '<<i+1<<endl;
int x; cin>>x;
if(x==1)
{
int val=i-1;
if(val==0) val=i+2;
cout<<"? "<<i<<' '<<val<<endl;
int temp; cin>>temp;
if(temp==1)
{
if(val==i+2) val++;
else val--;
cout<<"? "<<i<<' '<<val<<endl;
int t;cin>>t;
if(t)
{
cout<<"! 2\n";
return ;
} else
{
cout<<"! 1\n";
return ;
}
}
cout<<"? "<<i+1<<' '<<val<<endl;
cin>>temp;
if(temp==1)
{
if(val==i+2) val++;
else val--;
cout<<"? "<<i+1<<' '<<val<<endl;
int t;cin>>t;
if(t)
{
cout<<"! 2\n";
return ;
} else
{
cout<<"! 1\n";
return ;
}
}else cout<<"! 1\n";
return ;
}
}
for(int i=1;i<=3;i++)
{
cout<<"? "<<n<<i<<' ';
int temp; cin>>temp;
if(temp==0) flag=0;
}
if(flag) cout<<"! 2\n";
else cout<<"! 1\n";
} else
{
for(int i=1;i<n;i+=2)
{
cout<<"? "<<i<<' '<<i+1<<endl;
int x; cin>>x;
if(x==1)
{
int val=i-1;
if(val==0) val=i+2;
cout<<"? "<<i<<' '<<val<<endl;
int temp; cin>>temp;
if(temp==1)
{
if(val==i+2) val++;
else val--;
cout<<"? "<<i<<' '<<val<<endl;
int t;cin>>t;
if(t)
{
cout<<"! 2\n";
return ;
} else
{
cout<<"! 1\n";
return ;
}
}
cout<<"? "<<i+1<<' '<<val<<endl;
cin>>temp;
if(temp==1)
{
if(val==i+2) val++;
else val--;
cout<<"? "<<i+1<<' '<<val<<endl;
int t;cin>>t;
if(t)
{
cout<<"! 2\n";
return ;
} else
{
cout<<"! 1\n";
return ;
}
}else cout<<"! 1\n";
return ;
}
}
cout<<"! 1\n";
}
return ;
}
signed main(){
//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T=1; 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: 3632kb
input:
2 4 1 0 1 0 4 0 1 1 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 2 ? 3 1 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3608kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0 0 0 0 1 1 1 7 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 10 ? 12 10 ? 12 9 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 13 12 ? 13 11 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 71
result:
wrong answer Integer 71 violates the range [1, 7] (test case 3)