QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#882542 | #9734. Identify Chord | HildaHu | WA | 1ms | 3584kb | C++14 | 1.5kb | 2025-02-05 09:13:26 | 2025-02-05 09:13:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int T, n, dis, res;
bool flag;
int query(int x, int y) {
x = (x - 1) % n + 1, y = (y - 1) % n + 1;
if (flag) x = n + 1 - x, y = n + 1 - y;
cout << "? " << x << " " << y << endl;
int tmp; cin >> tmp;
return tmp;
}
void ans(int x, int y) {
x = (x - 1) % n + 1, y = (y - 1) % n + 1;
if (flag) x = n + 1 - x, y = n + 1 - y;
cout << "! " << x << " " << y << endl;
cin >> res;
if (res == -1) exit(0);
}
int getx(int x, int y) {
int l = x, r = y, ret = -1;
if (l > r) r += n;
while (l <= r) {
int mid = (l + r) >> 1;
if (query(mid, y) == dis - (mid - x)) ret = mid, l = mid + 1;
else r = mid - 1;
}
return ret;
}
void solve1(int x, int y) {
x = getx(x, y);
ans(x, x + n / 2 - dis + 1);
}
void solve2(int x, int y) {
int rx = getx(x, y);
ans(rx, y + dis - (rx - x) - 1);
}
bool work(int x, int y) {
dis = query(x, y);
if (dis == n / 2) return false;
bool dx = query(x + 1, y) == dis - 1;
bool dy = query(x, y + 1) == dis - 1;
if (dx && !dy) solve1(x, y);
else if (!dx && dy) solve1(y, x);
else if (dx && dy) solve2(x, y);
else flag = true, solve2(n + 1 - x, n + 1 - y);
return true;
}
int main() {
cin >> T;
while (T--) {
cin >> n; flag = false;
int x = 1, y = x + n / 2;
while (!work(x, y)) {
if (n & 1) {
if ((y - x + n) % n == n / 2 + 1) x = x % n + 1;
else y = y % n + 1;
} else x = x % n + 1, y = y % n + 1;
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
2 6 2 1 2 1 1 1 4 1 1 1 1 1 1
output:
? 1 4 ? 2 4 ? 1 5 ? 2 4 ? 3 4 ! 2 4 ? 1 3 ? 2 3 ? 1 4 ? 4 3 ? 1 3 ! 1 3
result:
ok ok (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3584kb
input:
1000 15 5 4 6 2 2 1 1 19 5 4 4 5 4 3 4 1 17 5 4 4 4 4 3 4 1 15 6 6 7 4 7 6 1 14 5 4 6 4 4 5 1 15 3 2 2 4 2 3 1 17 8 8 8 7 6 6 5 6 5 4 1 20 6 7 7 5 8 6 7 1 13 5 5 6 2 2 3 1 18 3 4 2 5 2 3 1 13 4 5 3 3 3 2 -1
output:
? 1 8 ? 2 8 ? 1 9 ? 4 8 ? 6 8 ? 5 8 ! 5 8 ? 1 10 ? 2 10 ? 1 11 ? 5 10 ? 2 10 ? 3 10 ? 4 10 ! 3 12 ? 1 9 ? 2 9 ? 1 10 ? 5 9 ? 2 9 ? 3 9 ? 4 9 ! 3 11 ? 1 8 ? 2 8 ? 1 9 ? 12 8 ? 15 8 ? 1 8 ! 1 3 ? 1 8 ? 2 8 ? 1 9 ? 4 8 ? 2 8 ? 3 8 ! 2 5 ? 1 8 ? 2 8 ? 1 9 ? 4 8 ? 2 8 ? 3 8 ! 2 9 ? 1 9 ? 1 10 ? 2 10 ? 2 ...
result:
wrong answer Wrong answer n=13, actual=9-13, guessed=9-12 (test case 11)