QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#637476 | #8239. Mysterious Tree | wzxtsl | RE | 1ms | 3644kb | C++23 | 4.0kb | 2024-10-13 13:00:46 | 2024-10-13 13:00:52 |
Judging History
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;
}
if(cnt==0){
cout<<"? "<<n<<" "<<1<<endl;
cout.flush();
cin>>num;
if(num==1) cnt++;
cout<<"? "<<n<<" "<<2<<endl;
cout.flush();
cin>>num;
if(num==1) cnt++;
cout<<"? "<<n<<" "<<3<<endl;
cout.flush();
cin>>num;
if(num==1) cnt++;
if(cnt==3){
cout<<"! 2"<<endl;
return ;
}else{
cout<<"! 1"<<endl;
return ;
}
}else if(cnt==1){
int a[3],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{
cout<<"! 1"<<endl;
return ;
}
}
}
signed main(){
int t=1;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
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
Runtime Error
input:
87 13 0 0 0 0 0 1 0 1 1
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 1 11 ? 1 12 ? 2 12