QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#417845#8239. Mysterious TreeAndevikingTL 0ms3504kbC++201.2kb2024-05-22 23:31:332024-05-22 23:31:34

Judging History

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

  • [2024-05-22 23:31:34]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3504kb
  • [2024-05-22 23:31:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define range(x) (x).begin(),(x).end()
const int dir[][2]={1,0,-1,0,0,1,0,-1};

int ask(int u,int v)
{
    cout<<"? "<<u<<' '<<v<<endl;
    int ans;
    cin>>ans;
    return ans;
}
void solve()
{
    int n;
    cin>>n;

    for(int i=1;i<=n;i+=2){
        int now;
        int v;
        if(i==n)
            now = ask(i,i-1),v=i-1;
        else 
            now = ask(i,i+1),v=i+1;

        if(now){
            int p=1;
            while(p==i||p==v)
                ++p;

            int root=i;
            now=ask(i,p);
            if(!now){
                now=ask(v,p);
                if(!now){
                    cout<<"! 1"<<endl;
                    return;
                }
                root=v;
            }

            int q=1;
            while(q==i||q==p||q==v)
                ++q;
            now=ask(root,q);
            if(now)
                cout<<"! 2"<<endl;
            else
                cout<<"! 1"<<endl;

            return;
        }
    }
}

int main()
{
    int t = 1;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3504kb

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 1
? 3 2
! 2

result:

ok Correct (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

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
1
1
1
15
0
0
0
1
0
0
19
0
0
0
0
0
1
1
1
20
0
0
0
0
0
0
0
0
0
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 11 1
? 12 1
? 12 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 13 1
? 13 2
! 2
? 1 2
? 3 4
? 5 6
? 7 6
? 7 1
? 7 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 7 1
? 8 1
! 1
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 11 1
? 11 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 1...

result: