QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#623175#8239. Mysterious TreeZhou_JKTL 0ms0kbC++141.2kb2024-10-09 10:29:052024-10-09 10:29:05

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 10:29:05]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [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

result: