QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771363 | #8239. Mysterious Tree | Konggee | WA | 1ms | 3592kb | C++20 | 1.5kb | 2024-11-22 12:10:20 | 2024-11-22 12:10:29 |
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) {
for (int i = 1; i <= n; i ++) {
if (i != x && i != y) {
if (ask(x, i)) {
for (int j = 1; j <= n; j ++) {
if (j != i && j != x && j != y) {
if (ask(x, j)) {
std::cout << "! 2" << std::endl;
return 0;
} else {
std::cout << "! 1" << std::endl;
return 1;
}
}
}
} else {
if (ask(y, i)) {
for (int j = 1; j <= n; j ++) {
if (j != i && j != x && j != y) {
if (ask(y, j)) {
std::cout << "! 2" << std::endl;
return 0;
} else {
std::cout << "! 1" << std::endl;
return 1;
}
}
}
} else {
std::cout << "! 1" << std::endl;
return 1;
}
}
}
}
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: 1ms
memory: 3524kb
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: 1ms
memory: 3592kb
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)