QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#523727 | #8239. Mysterious Tree | asitshouldbe | TL | 0ms | 0kb | C++14 | 1.7kb | 2024-08-18 17:01:43 | 2024-08-18 17:01:47 |
answer
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#define x first
#define y second
#define endl '\n'
#define pi acos(-1.0)
using namespace std;
typedef pair<int, int> PII;
typedef pair<double, int> PDI;
typedef pair<PII, int> PIII;
typedef pair<PII, char> PIIC;
typedef long long LL;
int dx[] = {1, 0, 0, -1, -1, -1, 1, 1}, dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
int mou[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int N = 1e3 + 10, M = 110, mod = 998244353, INF = 0x3f3f3f3f;
const double eps = 1e-8;
int n,m,t;
int input(int a,int b)
{
cout<<"? "<<a<<" "<<b<<endl;
fflush(stdout);
int c;cin>>c;
return c;
}
void output(int a)
{
cout<<"! "<<a<<endl;
fflush(stdout);
}
void solve()
{
cin>>n;
int pos=-1,cnt=0;
for(int i=1;i+1<=n;i+=2)
{
int x=input(i,i+1);
if(x)
{
cnt++;
pos=i;
}
}
if(n%2)
{
int x=input(n-1,n);
if(x)
{
cnt++;
pos=n-1;
}
}
if(cnt!=1)
{
output(1);
return;
}
int a=pos,b=pos+1;
int x=input(a,b%n+1),y=input(b,b%n+1);
if(!x&&!y) output(1);
else if(x)
{
int z=input(a,a==1?n:a-1);
if(z) output(2);
else output(2);
}
else if(y)
{
int z=input(b,a==1?n:a-1);
if(z) output(2);
else output(2);
}
}
int main()
{
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0),cout.precision(10);
// freopen("in.in","r",stdin);
// freopen("test.out","w",stdout);
t=1; cin >> t;
while (t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 4