QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#547926 | #8239. Mysterious Tree | pengpeng_fudan# | WA | 1ms | 3828kb | C++23 | 1.4kb | 2024-09-05 13:19:36 | 2024-09-05 13:19:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int query(int x, int y) {
cout << "? " << x << ' ' << y << endl;
int z;
cin >> z;
return z;
}
void solve() {
int n;
scanf("%d", &n);
int x = 0, y = 0;
if (n & 1) {
for (int i = 1; i < n; i += 2) {
if (query(i, i + 1)) {
x = i, y = i + 1;
}
}
if (query(1, n)) {
x = 1, y = n;
}
}
else {
for (int i = 1; i <= n; i += 2) {
if (query(i, i + 1)) {
x = i, y = i + 1;
}
}
}
if (!x && !y) {
cout << "! 1" << endl;
}
else {
int a1 = 0, a2 = 0;
for (int i = 1; i <= n; ++i) {
if (i != x && i != y) {
a1 = i;
break;
}
}
int v1 = query(x, a1), v2 = query(y, a1);
if (!v1 && !v2) {
cout << "! 1" << endl;
}
if (!v1) swap(x, y);
for (int i = 1; i <= n; ++i) {
if (i != x && i != y && i != a1) {
a2 = i;
break;
}
}
if (query(a2, x)) {
cout << "! 2" << endl;
}
else {
cout << "! 1" << endl;
}
}
}
int main() {
int T;
scanf("%d", &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: 3632kb
input:
2 4 1 1 0 0 4 0
output:
? 1 2 ? 3 4 ? 3 1 ? 4 1 ! 1 ? 2 4 ! 2 ! 1
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3828kb
input:
87 13 0 0 0 0 0 1 0 0 1 1 15 0 0 0 0 0 0 1 0 1 0 1 7 0 0 0 1 0 1 1 15 0 0 0 1 1 0 0 1 0 0 19 0 20 7 0 0 1
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 1 13 ? 11 1 ? 12 1 ? 2 12 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 1 15 ? 13 1 ? 14 1 ? 2 13 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 1 7 ? 1 2 ? 7 2 ? 3 7 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 1 15 ? 1 2 ? 15 2 ! 1 ? 3 15 ! 2 ! 1 ? 1 2 ? 3 4 ? 5 6 ...
result:
wrong answer Integer 8 violates the range [1, 7] (test case 7)