QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#623175 | #8239. Mysterious Tree | Zhou_JK | TL | 0ms | 0kb | C++14 | 1.2kb | 2024-10-09 10:29:05 | 2024-10-09 10:29:05 |
answer
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
int n;
int query(int x,int y)
{
cout<<"? "<<x<<" "<<y<<endl;
int val;
cin>>val;
return val;
}
void submit(int x)
{
cout<<"? "<<x<<endl;
return;
}
void solve()
{
cin>>n;
for(int i=1;i+1<=n;i+=2)
{
int u=i,v=i+1;
if(query(u,v))
{
int x=1;
while(x==u||x==v) x++;
if(query(u,x))
{
int y=1;
while(y==u||y==v||y==x) y++;
if(query(u,y)) return submit(2);
else return submit(1);
}
else if(query(v,x))
{
int y=1;
while(y==u||y==v||y==x) y++;
if(query(v,y)) return submit(2);
else return submit(1);
}
else return submit(1);
}
}
if(n&1)
{
int x=1,y=2,z=3;
if(query(n,x)&&query(n,y)&&query(n,z)) return submit(2);
else return submit(1);
}
return submit(1);
}
int main()
{
ios::sync_with_stdio(false);
//cin.tie(nullptr),cout.tie(nullptr);
int T;
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 1 0 1 0
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 1