QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#622072 | #8239. Mysterious Tree | zxk | WA | 1ms | 3652kb | C++17 | 1.3kb | 2024-10-08 19:45:18 | 2024-10-08 19:45:20 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e18;
typedef pair<int, int> PII;
typedef long long LL;
int n;
int query(int u, int v)
{
cout << "? " << u << ' ' << v << endl;
int res;
cin >> res;
return res;
}
int work1(int u)
{
int v = (u - 1) + n * (u <= 1);
int f = query(u, v);
if (!f) return 0;
v = (u - 2) + n * (u <= 2);
f = query(u, v);
if (!f) return 1;
else return 2;
}
int work2(int u)
{
int v = (u - 2) + n * (u <= 2);
int f = query(u, v);
if (!f) return 1;
v = (u - 3) + n * (u <= 3);
f = query(u, v);
if (!f) return 1;
else return 2;
}
void solve()
{
cin >> n;
for (int i = 1; i <= n; i += 2)
{
int res = query(i, i + 1);
if (res)
{
int f = work1(i);
if (f) cout << "! " << f << endl;
else
{
f = work2(i+1);
cout << "! " << f << endl;
}
return;
}
if (n % 2 && i == n)
{
int res = query(n - 1, n);
if (res)
{
int f = work1(n-1);
if (f) cout << "! " << f << endl;
else
{
f = work2(n);
cout << "! " << f << endl;
}
return;
}
}
}
cout << "! 1" << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T;
cin >> T;
while (T -- )
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3652kb
input:
2 4 1 0 0 4 0 1 1 1
output:
? 1 2 ? 1 4 ? 2 4 ! 1 ? 1 2 ? 3 4 ? 3 2 ? 3 1 ! 2
result:
ok Correct (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3640kb
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 10 ? 12 10 ? 12 9 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8 ? 9 10 ? 11 12 ? 13 14 ? 13 12 ? 13 11 ! 2 ? 1 2 ? 3 4 ? 5 6 ? 7 8
result:
wrong answer Integer 8 violates the range [1, 7] (test case 3)