QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#614034 | #8239. Mysterious Tree | klhwong# | TL | 0ms | 0kb | C++17 | 2.2kb | 2024-10-05 15:23:58 | 2024-10-05 15:24:13 |
answer
#include <bits/stdc++.h>
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;
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;
cin >> res;
if (res == 1) {
u = n - 1;
v = n;
x = 1;
y = 2;
flag = true;
}
}
if (!flag) {
cout << "! 2" << "\n";
} else {
q = "? " + to_string(u) + " " + to_string(x) + "\n";
cout << q;
cin >> res;
if (res == 0) {
q = "? " + to_string(v) + " " + to_string(x) + "\n";
cout << q;
cin >> res;
if (res == 0) {
cout << "! 1" << "\n";
} else {
q = "? " + to_string(v) + " " + to_string(y) + "\n";
cout << q;
cin >> res;
if (res == 1) {
cout << "! 2" << "\n";
} else {
cout << "! 1" << "\n";
}
}
} else {
q = "? " + to_string(u) + " " + to_string(y) + "\n";
cout << q;
cin >> res;
if (res == 0) {
cout << "! 1" << "\n";
} else {
cout << "! 2" << "\n";
}
}
}
}
cout.flush();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
2 4