QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#745545 | #8239. Mysterious Tree | zaqmju | WA | 1ms | 3632kb | C++23 | 1.1kb | 2024-11-14 10:30:57 | 2024-11-14 10:30:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
// #define endl '\n'
int ask(int u, int v) {
cout << "? " << u << " " << v << "\n";
fflush(stdout);
int g;
cin >> g;
return g;
}
void ans(int u) {
cout << "! " << u << "\n";
fflush(stdout);
}
void solve() {
bool flag = 1;
int x = 0, y = 0;
int n;
cin >> n;
for(int i = 1; i <= n; i += 2) {
int a = i;
int b = i + 1;
if(i == n)b = i - 1;
int t = ask(a, b);
if(t == 1) {
flag = false;
x = a, y = b;
break;
}
}
if(flag) {
ans(2);
}
else {
int a = 0, b = 0;
for(int i = 1; i <= n; i++) {
if(i != x && i != y) {
if(!a) a = i;
else if(!b) b = i;
else break;
}
}
int t = ask(x, a);
if(t == 1) {
t = ask(x, b);
if(t == 1)ans(1);
else ans(2);
}
else {
t = ask(y, a);
if(t == 1) {
t = ask(y, b);
if(t)ans(1);
else ans(2);
}
else ans(2);
}
}
}
#undef int
int main() {
// ios::sync_with_stdio(false);
// cin.tie(0);
int t = 1;
cin >> t;
while(t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3632kb
input:
2 4 1 0 1 0
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 2
result:
wrong answer Wrong prediction (test case 1)