QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#614052 | #8239. Mysterious Tree | klhwong# | WA | 1ms | 3544kb | C++17 | 2.6kb | 2024-10-05 15:29:25 | 2024-10-05 15:29:25 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int t, n, res, u, v, x, y;
bool flag;
string q;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> t;
while(t--) {
cin >> n;
flag = false;
for (int i = 1; i <= n; i += 2) {
q = "? " + to_string(i) + " " + to_string(i + 1) + "\n";
cout << q;
cout.flush();
cin >> res;
if (res == 1) {
u = i;
v = i + 1;
if (i == 1) {
x = n - 1;
y = n;
} else {
x = 1;
y = 2;
}
flag = true;
break;
}
}
if (!flag && n % 2 == 1) {
q = "? " + to_string(n - 1) + " " + to_string(n) + "\n";
cout << q;
cout.flush();
cin >> res;
if (res == 1) {
u = n - 1;
v = n;
x = 1;
y = 2;
flag = true;
}
}
if (!flag) {
cout << "! 2" << "\n";
cout.flush();
} else {
q = "? " + to_string(u) + " " + to_string(x) + "\n";
cout << q;
cout.flush();
cin >> res;
if (res == 0) {
q = "? " + to_string(v) + " " + to_string(x) + "\n";
cout << q;
cout.flush();
cin >> res;
if (res == 0) {
cout << "! 1" << "\n";
cout.flush();
} else {
q = "? " + to_string(v) + " " + to_string(y) + "\n";
cout << q;
cout.flush();
cin >> res;
if (res == 1) {
cout << "! 2" << "\n";
cout.flush();
} else {
cout << "! 1" << "\n";
cout.flush();
}
}
} else {
q = "? " + to_string(u) + " " + to_string(y) + "\n";
cout << q;
cout.flush();
cin >> res;
if (res == 0) {
cout << "! 1" << "\n";
cout.flush();
} else {
cout << "! 2" << "\n";
cout.flush();
}
}
}
}
cout.flush();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3544kb
input:
2 4 1 0 1 0 4 0 1 1 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 3 2 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3500kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0 0 0 0 1 1 1 7 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 11 1 ? 12 1 ? 12 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 13 1 ? 13 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8
result:
wrong answer Integer 8 violates the range [1, 7] (test case 3)