QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#326636 | #8239. Mysterious Tree | james1BadCreeper# | WA | 1ms | 3548kb | C++14 | 1.1kb | 2024-02-13 17:13:11 | 2024-02-13 17:13:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
int n;
int ask(int u, int v) {
cout << "? " << u << " " << v << endl;
return cin >> u, u;
}
void solve(void) {
cin >> n;
int u = -1, v = -1;
for (int i = 1; i <= n; i += 2)
if (ask(i, i + 1)) { u = i, v = i + 1; break; }
if (u == -1 && ask(n - 1, n)) u = n - 1, v = n;
if (u == -1) return cout << "! 1" << endl, void(); // 一定不是菊花
int t1 = -1, t2 = -1;
for (int i = 1; i <= n; ++i) if (i != u && i != v) { t1 = i; break; }
for (int i = 1; i <= n; ++i) if (i != u && i != v && i != t1) { t2 = i; break; }
int x = ask(u, t1), y = ask(v, t1);
// cout << u << " " << v << "\n";
// cout << x << " " << y << "\n";
if (!x && !y) return cout << "! 1" << endl, void();
if (x && ask(u, t2)) return cout << "! 2" << endl, void();
if (y && ask(v, t2)) return cout << "! 2" << endl, void();
cout << "! 1" << endl;
}
int main(void) {
ios::sync_with_stdio(0);
int T; 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: 3548kb
input:
2 4 1 0 1 0 4 0 1 1 0 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 1 ? 4 1 ? 3 2 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3544kb
input:
87 13 0 0 0 0 0 1 0 1 1 15 0 0 0 0 0 0 1 1 0 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 ? 14 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)