QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693152 | #8239. Mysterious Tree | wang_xy# | TL | 1ms | 3896kb | C++20 | 2.8kb | 2024-10-31 15:37:51 | 2024-10-31 15:37:53 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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