QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771725 | #8239. Mysterious Tree | Konggee | WA | 2ms | 3688kb | C++20 | 1.1kb | 2024-11-22 15:17:48 | 2024-11-22 15:17:49 |
Judging History
answer
#include <bits/stdc++.h>
std::mt19937_64 rng {std::chrono::steady_clock::now().time_since_epoch().count()};
int n;
int ask(int x, int y) {
std::cout << "? " << x << " " << y << std::endl;
int res;
std::cin >> res;
return res;
}
int ok(int x, int y) {
int p1 = -1, p2 = -1;
for (int i = 1; i <= n; i ++) {
if (i != x && i != y) {
if (p1 == -1) {
p1 = i;
} else {
p2 = i;
break;
}
}
}
if (ask(x, p1) && ask(x, p2) || ask(y, p1) && ask(y, p2)) {
std::cout << "! 2" << std::endl;
return 0;
}
std::cout << "! 1" << std::endl;
return 1;
}
void solve() {
std::cin >> n;
int cnt = (n + 1) / 2 + 3;
int l = 1, r = 2;
while (cnt --) {
if (l > n || r > n) {
break;
}
if (ask(l, r)) {
ok(l, r);
} else {
l += 2, r += 2;
}
}
if (n % 2 == 0) {
std::cout << "! 1" << std::endl;
} else {
if (ask(n, 1)) {
ok(n, 1);
} else if (ask(n, 2)) {
ok(n, 2);
} else {
std::cout << "! 1" << std::endl;
}
}
return;
}
int main() {
int t;
std::cin >> t;
while (t --) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
input:
2 4 1 0 1 0 4 0 1 1 0
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 2 ? 1 2 ? 3 4
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3688kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 12 1 ? 12 2 ! 2 ? 11 12 ? 11 1 ? 12 1 ! 1 ? 11 12 ? 13 1
result:
wrong answer Wrong prediction (test case 2)