QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693152#8239. Mysterious Treewang_xy#TL 1ms3896kbC++202.8kb2024-10-31 15:37:512024-10-31 15:37:53

Judging History

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

  • [2024-10-31 15:37:53]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3896kb
  • [2024-10-31 15:37:51]
  • 提交

answer

#include <bits/stdc++.h>
#define int int
#define ll int
#define ff fflush(stdout)
using namespace std;
int query(int x,int y){
    printf("? %d %d\n",x,y);
    ff;
    scanf("%d",&x);
    return x;
}
void print(int x){
    printf("! %d\n",x);
    ff;
}
void solve() {
    ll n;
    cin>>n;
    ll cnt=0;
    ll a,b;
    if(n%2==1){
        for(ll i=2;i<=n;i+=2){
            ll x=query(i-1,i);
            if(x==1){
                cnt++;
                a=i-1,b=i;
            }
        }
        if(cnt>1){
            print(1);
        }
        else if(cnt==0){
            ll x=query(n-1,n);
            ll y=query(n-2,n);
            ll z=query(n-3,n);
            if(x+y+z!=3)
                print(1);
            else
                print(2);
        }
        else{
            ll A,B;
            for(ll i=1;i<n;i+=2){
                if(i!=a){
                    A=i,B=i+1;
                    break;
                }
            }
            ll x=query(A,a);
            if(x==1){
                x=query(B,a);
                if(x==1){
                    print(2);
                }
                else{
                    x=query(A,b);
                    if(x==1){
                        x=query(B,b);
                        if(x==1){
                            print(2);
                        }
                        else{
                            print(1);
                        }
                    }
                    else{
                        print(1);
                    }
                }
            }
        }
    }
    else{
        for(ll i=2;i<=n;i+=2){
            ll x=query(i-1,i);
            if(x==1){
                cnt++;
                a=i-1,b=i;
            }
        }
        if(cnt!=1){
            print(1);
        }
        else{
            ll A,B;
            for(ll i=1;i<n;i+=2){
                if(i!=a){
                    A=i,B=i+1;
                    break;
                }
            }
            ll x=query(A,a);
            if(x==1){
                x=query(B,a);
                if(x==1){
                    print(2);
                }
                else{
                    x=query(A,b);
                    if(x==1){
                        x=query(B,b);
                        if(x==1){
                            print(2);
                        }
                        else{
                            print(1);
                        }
                    }
                    else{
                        print(1);
                    }
                }
            }
        }
    }
}

signed main() {
//    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    ll t;
    cin>>t;
    while (t--)
        solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3896kb

input:

2
4
1
1
4
0
1
1
1

output:

? 1 2
? 3 4
! 1
? 1 2
? 3 4
? 1 3
? 2 3
! 2

result:

ok Correct (2 test cases)

Test #2:

score: -100
Time Limit Exceeded

input:

87
13
0
0
0
0
0
1
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 1 11

result: