QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637425#8239. Mysterious TreewzxtslWA 1ms3716kbC++233.4kb2024-10-13 12:47:002024-10-13 12:47:01

Judging History

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

  • [2024-10-13 12:47:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3716kb
  • [2024-10-13 12:47:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e6+7;
int n,m;
void solve(){
	cin>>n;
    if(n%2==0){
        int cnt=0,i,j,num;
        for(int k=1;k<=n;k+=2){
            cout<<"? "<<k<<" "<<k+1<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++,i=k,j=k+1;
        }
        if(cnt!=1){
            cout<<"! 1"<<endl;
            return ;
        }
        int a[3];
        int cn=0;
        for(int k=1;k<=n;k++){
            if(k!=i&&k!=j){
                a[++cn]=k;
            }
        }
        cout<<"? "<<a[1]<<" "<<i<<endl;
        cout.flush();
        cin>>num;
        if(num==1){
            cout<<"? "<<a[2]<<" "<<i<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"! 2"<<endl;
                return ;
            }else{
                cout<<"! 1"<<endl;
            }
        }else{
            cout<<"? "<<a[1]<<" "<<j<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"? "<<a[2]<<" "<<j<<endl;
                cout.flush();
                cin>>num;
                if(num==1){
                    cout<<"! 2"<<endl;
                    return ;
                }else{
                    cout<<"! 1"<<endl;
                    return ;
                }
            }else{
                cout<<"! 1"<<endl;
                return ;
            }
        }
    }else{
        int cnt=0,i,j,num;
        for(int k=1;k<=n&&k+1<=n;k+=2){
            cout<<"? "<<k<<" "<<k+1<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++,i=k,j=k+1;
        }
        cout<<"? "<<n-1<<" "<<n<<endl;
        cout.flush();
        cin>>num;
        if(num==1) cnt++,i=n-1,j=n;
        if(cnt!=1){
            cout<<"! 1"<<endl;
            return ;
        }
        int a[3];
        int cn=0;
        for(int k=1;k<=n;k++){
            if(k!=i&&k!=j){
                a[++cn]=k;
            }
        }
        cout<<"? "<<a[1]<<" "<<i<<endl;
        cout.flush();
        cin>>num;
        if(num==1){
            cout<<"? "<<a[2]<<" "<<i<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"! 2"<<endl;
                return ;
            }else{
                cout<<"! 1"<<endl;
            }
        }else{
            cout<<"? "<<a[1]<<" "<<j<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"? "<<a[2]<<" "<<j<<endl;
                cout.flush();
                cin>>num;
                if(num==1){
                    cout<<"! 2"<<endl;
                    return ;
                }else{
                    cout<<"! 1"<<endl;
                    return ;
                }
            }else{
                cout<<"! 1"<<endl;
                return ;
            }
        }
    }
}
signed main(){
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}

詳細信息

Test #1:

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

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
Wrong Answer
time: 0ms
memory: 3716kb

input:

87
13
0
0
0
0
0
1
1

output:

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

result:

wrong answer Wrong prediction (test case 1)