QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#406126 | #8239. Mysterious Tree | oscaryang | TL | 1ms | 3664kb | C++20 | 2.3kb | 2024-05-06 20:36:44 | 2024-05-06 20:36:44 |
Judging History
answer
//OccDreamer
#include<bits/stdc++.h>
#define fi first
#define se second
#define vc vector
#define db double
#define ll long long
#define mk make_pair
#define pb push_back
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << " -_- " << endl
#define debug cerr << " ------------------- " << endl
#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)
#define NO puts("No")
#define YES puts("Yes")
//#define int long long
using namespace std;
namespace IO{
inline int read(){
int X=0, W=0; char ch=getchar();
while(!isdigit(ch)) W|=ch=='-', ch=getchar();
while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
return W?-X:X;
}
inline void write(int x){
if(x<0) x=-x, putchar('-');
if(x>9) write(x/10);
putchar(x%10+'0');
}
inline void sprint(int x){write(x), putchar(32);}
inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;
const int MAXN = 3005;
const int mod = 998244353;
//const int mod = 1e9+7;
int ca[MAXN], n;
inline void solve(){
n=read();
for(int i=1;i<=n;i+=2) ca[i]=i+1;
if(n&1) ca[n]=n-1; int x, y;
for(int i=1;i<=n;i+=2){
cout << "? " << i << ' ' << ca[i] << endl;
bool res; cin >> res;
if(res==1) x=i, y=ca[i];
}
bool okx=0, oky=0; int cx, cy;
for(int i=1;i<=n;++i){
if(i!=x && i!=y){
cx=i;
cout << "? " << x << ' ' << i << endl;
cin >> okx; break;
}
}
for(int i=1;i<=n;++i){
if(i!=x && i!=y){
cy=i;
cout << "? " << y << ' ' << i << endl;
cin >> oky; break;
}
}
if(!okx && !oky){cout << "! 1" << endl; return ;}
if(okx && oky){cout << "! 1" << endl; return ;}
if(okx){
for(int i=1;i<=n;++i){
if(i!=x && i!=y && i!=cx){
cout << "? " << x << ' ' << i << endl;
cin >> okx;
if(okx==1){cout << "! 2" << endl; return ;}
cout << "! 1" << endl; return ;
}
}
}
for(int i=1;i<=n;++i){
if(i!=x && i!=y && i!=cy){
cout << "? " << y << ' ' << i << endl;
cin >> okx;
if(okx==1){cout << "! 2" << endl; return ;}
cout << "! 1" << endl; return ;
}
}
}
int main(){
int t=read();
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
input:
2 4 1 1 0 0 4 0 1 1 0 1
output:
? 1 2 ? 3 4 ? 3 1 ? 4 1 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 4 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 1 0 1 1 15 0 0 0 0 0 0 1 0 1 0 1 7 0 0 0 1 1 0 1 15 0 0 0 1 1 0 0 0 1 0 0 19 0 0 0 0 0 1 0 0 0 0 1 0 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 ? 13 12 ? 13 1 ? 12 1 ? 12 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 15 14 ? 13 1 ? 14 1 ? 13 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 6 ? 7 1 ? 6 1 ? 7 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 15 14 ? 9 1 ? 10 1 ? 9 2 ! 1 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ...