QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#323827 | #8239. Mysterious Tree | ucup-team1516# | WA | 1ms | 3700kb | C++17 | 2.2kb | 2024-02-10 13:36:58 | 2024-02-10 13:36:59 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q; cin >> q;
while (q--) {
int n; cin >> n;
auto query = [](int x, int y) -> int {
cout << "? " << x+1 << " " << y+1 << endl;
int res; cin >> res; return res;
};
int a = -1, b = -1;
for (int i = 0; i+1 < n; i += 2) {
if (query(i, i+1)) {
a = i, b = i+1;
break;
}
}
if (n%2) {
if (query(n-2, n-1)) {
a = n-2, b = n-1;
}
}
if (a != -1) {
auto star = [&](int a, int b) -> bool {
for (int i = 0; i < n; ++i) {
if (i == a or i == b) continue;
if (query(a, i)) {
for (int j = i+1; j < n; ++j) {
if (j == a or j == b) continue;
if (query(a, j)) return true;
else return false;
}
}
else {
break;
}
}
for (int i = 0; i < n; ++i) {
if (i == a or i == b) continue;
if (query(b, i)) {
for (int j = i+1; j < n; ++j) {
if (j == a or j == b) continue;
if (query(b, j)) return true;
else return false;
}
}
}
return false;
};
if (star(a, b)) {
cout << "! " << 2 << endl;
continue;
}
}
cout << "! " << 1 << endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
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: 3700kb
input:
87 13 0 0 0 0 0 1 1 1 1 15 0 0 0 0 0 0 1 0 1 1 7 0 0 0 1 0 1 1 15 0 0 0 1 0 0 0 0 0 0 0
output:
? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 12 13 ? 12 1 ? 12 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 14 15 ? 13 1 ? 13 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 6 7 ? 6 1 ? 7 1 ? 7 2 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 14 15 ? 7 1 ? 8 1 ? 8 2 ? 8 3 ? 8 4 ? 8 5 ? 8 6
result:
wrong answer Too many queries , n = 15 , now_q 12 (test case 4)