QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#628054 | #8239. Mysterious Tree | zzxdashuaibi | WA | 1ms | 3624kb | C++20 | 1.7kb | 2024-10-10 18:23:48 | 2024-10-10 18:23:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) x & -x
#define int long long
#define pii pair<int ,int >
#define fi first
#define se second
#define ull unsigned long long
#define find1(x) __builtin_popcount(x)
const int N = 1e5 + 10, inf = 0x3f3f3f3f, mod = 1e9 + 7,INF=0x3f3f3f3f3f3f3f3f;
mt19937_64 rnd(random_device{}());
uniform_int_distribution<ull> dist(0, ULLONG_MAX); // use dist(rnd)
void solve() {
int n ;
cin >> n ;
auto get =[&](int u , int v) -> int
{
int x;
cout << "? " << u << ' ' << v << endl;
cin >> x;
return x;
};
pii pre = {0 , 0};
for(int i = 1 ; i + 1<= n ; i += 2 )
{
int tt = get(i , i + 1);
if(tt)
{
pre = {i , i + 1};
break;
}
}
if(n & 1)
{
int tt = get(1 , n);
if(tt)
{
pre = {1 , n};
}
}
auto FindTwo = [&](int u , int v) ->pii
{
pii ans = { 0 , 0};
for(int i = 1; i <= n ; i ++)
{
if(i != u && i != v && !ans.fi) ans.fi = i;
else if (i != u && i != v && !ans.se)
{
ans.se = i;
break;
}
}
return ans;
};
auto check = [&](int u , int v) -> bool
{
auto [p1, p2] = FindTwo(u , v);
if(!get(u ,p1))
{
v = u;
}
if(get(u,p1) && get(u , p2))
{
return true;
}
else return false;
};
if(pre.fi == 0)
{
cout << "! " << 1 << endl;
}
else
{
int tt = check(pre.fi , pre.se);
if(tt) cout << "! " << 2 << endl;
else cout << "! " << 1 << endl;
}
}
/*
*/
#undef int
int main() {
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cout<<fixed<<setprecision(15);
int _ = 1;cin >>_;while(_--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3496kb
input:
2 4 1 0 0 4 0 1 1 1 1
output:
? 1 2 ? 1 3 ? 1 3 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 3 1 ? 3 2 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3624kb
input:
87 13 0 0 0 0 0 1 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 1 13 ? 11 1 ? 11 1 ! 1
result:
wrong answer Wrong prediction (test case 1)