QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#393346 | #8239. Mysterious Tree | ucup-team3282# | WA | 0ms | 3816kb | C++14 | 1.9kb | 2024-04-18 15:32:08 | 2024-04-18 15:32:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main() {
int T; cin >> T;
while (T--) {
int n, cc = 0;
cin >> n;
set<int> v;
for (int i = 1; i <= n / 2; i++) {
printf("? %d %d\n", i * 2, i * 2 + 1);
int c;
cin >> c;
if (c == 1) {
v.insert(i * 2);
v.insert(i * 2 + 1);
cc++;
}
}
if (n % 2 == 1) {
printf("? %d %d\n", n - 1, n);
int c;
cin >> c;
if (c == 1) {
v.insert(n - 1);
v.insert(n);
cc++;
}
}
if (cc == 0) {
printf("! 1\n");
fflush(stdout);
continue;
}
if (n % 2 == 1) {
if (v.find(n - 2) != v.end() && v.find(n) != v.end()) {
printf("? 1 %d\n", n - 1);
int c;
cin >> c;
if (c == 1) {
printf("! 2\n");
fflush(stdout);
continue;
}
else {
printf("! 2\n");
fflush(stdout);
continue;
}
}
}
if (cc > 1) {
printf("! 1\n");
fflush(stdout);
continue;
}
int a = -1, b = -1, e, f, g, h, j;
for (auto it = v.begin(); it != v.end(); it++) {
if (a == -1) a = *it;
else b = *it;
}
if (a == 1) e = n;
else e = a - 1;
if (b == n) f = 1;
else f = b + 1;
printf("? %d %d\n", a, e);
cin >> g;
printf("? %d %d\n", b, e);
cin >> h;
if (g == 1 && h == 1) {
printf("! 1\n");
fflush(stdout);
continue;
}
if (g == 1) {
printf("? %d %d\n", a, f);
cin >> j;
if (j == 1) {
printf("! 2\n");
fflush(stdout);
continue;
} else {
printf("! 1\n");
fflush(stdout);
continue;
}
}
if (h == 1) {
printf("? %d %d\n", b, f);
cin >> j;
if (j == 1) {
printf("! 2\n");
fflush(stdout);
continue;
} else {
printf("! 1\n");
fflush(stdout);
continue;
}
}
if (g == 0 && h == 0) {
printf("! 1\n");
fflush(stdout);
continue;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3816kb
input:
2 4 1
output:
? 2 3 ? 4 5
result:
wrong answer Integer 5 violates the range [1, 4] (test case 1)