QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#885617 | #9734. Identify Chord | Air_Color5 | WA | 1ms | 3840kb | C++14 | 1.2kb | 2025-02-06 16:39:10 | 2025-02-06 16:39:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n;
int Query(int a, int b) {
if (a == b) {
return 0;
}
printf("? %d %d\n", a, b);
fflush(stdout);
int v;
scanf("%d", &v);
return v;
}
inline int Prev(int a) {
return (a == 1 ? n : a - 1);
}
inline int Next(int a) {
return (a == n ? 1 : a + 1);
}
inline int Walk(int a, long long b) {
return (((long long)a + b) % n + n - 1) % n + 1;
}
random_device rd;
mt19937 mt(rd());
void Solve() {
scanf("%d", &n);
int a, b, DIS;
a = 1, b = 1 + n / 2;
if (Query(a, b) == n / 2 and n % 2 == 1) {
b++;
}
if (Query(a, b) == n / 2) {
a++;
Walk(b, 1);
}
DIS = Query(a, b);
int d;
if (Query(Prev(a), b) == DIS - 1) {
d = -1;
}
else {
d = 1;
}
for (int i = __lg(n) - 1; i >= 0; i--) {
int A = Walk(a, d * (1 << i));
int D = Query(A, b);
if ((1ll << i) + D == DIS) {
DIS = D;
a = A;
}
}
if (Query(a, Walk(b, DIS - 1)) == 1) {
b = Walk(b, DIS - 1);
}
else {
b = Walk(b, 1 - DIS);
}
printf("! %d %d\n", a, b);
fflush(stdout);
int res;
scanf("%d", &res);
if (res == -1) {
exit(0);
}
}
signed main() {
int t;
scanf("%d", &t);
while (t--) {
Solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3840kb
input:
2 6 2 2 2 2 1 1 1 1 4 1 1 1 1 1 1 1
output:
? 1 4 ? 1 4 ? 1 4 ? 6 4 ? 3 4 ? 2 4 ? 2 4 ! 2 4 ? 1 3 ? 1 3 ? 1 3 ? 4 3 ? 2 3 ? 1 3 ! 1 3
result:
ok ok (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3840kb
input:
1000 15 5 5 5 6 1 1 2 1 1 19 5 5 5 6 1 5 3 4 1 1 17 5 5 5 6 4 3 4 1 1 15 6 6 6 7 3 5 6 3 1 14 5 5 5 6 3 5 4 5 1 15 3 3 3 4 3 3 2 1 1 17 8 8 8 8 4 2 1 1 -1
output:
? 1 8 ? 1 8 ? 1 8 ? 15 8 ? 5 8 ? 7 8 ? 6 8 ? 5 8 ! 5 8 ? 1 10 ? 1 10 ? 1 10 ? 19 10 ? 9 10 ? 5 10 ? 3 10 ? 4 10 ? 3 12 ! 3 12 ? 1 9 ? 1 9 ? 1 9 ? 17 9 ? 5 9 ? 3 9 ? 4 9 ? 3 11 ! 3 11 ? 1 8 ? 1 8 ? 1 8 ? 15 8 ? 5 8 ? 3 8 ? 2 8 ? 1 13 ! 1 3 ? 1 8 ? 1 8 ? 1 8 ? 14 8 ? 5 8 ? 3 8 ? 2 8 ? 2 11 ! 2 5 ? 1 8...
result:
wrong answer Wrong answer n=17, actual=5-14, guessed=10-9 (test case 7)