QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#882658#9734. Identify ChordforgotmyhandleRE 1ms3584kbC++142.4kb2025-02-05 10:31:522025-02-05 10:31:53

Judging History

This is the latest submission verdict.

  • [2025-02-05 10:31:53]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 3584kb
  • [2025-02-05 10:31:52]
  • Submitted

answer

#include <iostream>
#include <cassert>
#define int long long
using namespace std;
int n;
int dist(int x, int y) {
    if (x > y) 
        swap(x, y);
    return min(y - x, n - y + x);
}
int query(int x, int y) {
    cout << "? " << x + 1 << " " << y + 1 << endl;
    int ret = 0;
    cin >> ret;
    return ret;
}
void answer(int x, int y) {
    cout << "! " << x + 1 << " " << y + 1 << endl;
    int ret = 0;
    cin >> ret;
    if (ret == -1) 
        exit(0);
}
int f(int x) { return (x + n * 10) % n; }
signed main() {
    int tc;
    cin >> tc;
    while (tc--) {
        cin >> n;
        if (n <= 10) {
            bool ok = 0;
            for (int i = 0; i < n && !ok; i++) {
                for (int j = 0; j < n && !ok; j++) {
                    if (dist(i, j) > 1 && query(i, j) == 1) {
                        answer(i, j);
                        ok = 1;
                    }
                }
            }
            continue;
        }
        int x = 0, y = n / 2;
        if ((n & 1) && query(x, y) == dist(x, y)) 
            ++y;
        if (query(x, y) == dist(x, y)) 
            ++x, ++y;
        int d = query(x, y);
        assert(d != dist(x, y));
        if (d == 1) {
            answer(x, y);
            continue;
        }
        int ql = query(f(x - 1), y), qr = query(x + 1, y), p = -1, q = -1;
        if (ql > d && qr > d) 
            p = x;
        else {
            if (ql < d) {
                assert(ql < d);
                int l = 1, r = n / 2, mid, ans = -1;
                while (l <= r) {
                    mid = (l + r) >> 1;
                    if (d - query(f(x - mid), y) == mid) 
                        ans = mid, l = mid + 1;
                    else 
                        r = mid - 1;
                }
                p = f(x - ans);
            } else {
                assert(qr < d);
                int l = 1, r = n / 2, mid, ans = -1;
                while (l <= r) {
                    mid = (l + r) >> 1;
                    if (d - query(f(x + mid), y) == mid) 
                        ans = mid, l = mid + 1;
                    else 
                        r = mid - 1;
                }
                p = f(x + ans);
            }
        }
        int t = query(p, y) - 1;
        if (query(p, f(y - t)) == 1) 
            answer(p, f(y - t));
        else 
            answer(p, f(y + t));
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

input:

2
6
2
2
2
1
1
4
1
1

output:

? 1 3
? 1 4
? 1 5
? 2 4
! 2 4
? 1 3
! 1 3

result:

ok ok (2 test cases)

Test #2:

score: -100
Runtime Error

input:

1000
15
5
5
5
6
4
1
1
2
1
1
1
19
5
5
5
6
4
4
3
4
3
5
1
17
5
5
5
6
4
4
3
4
3
4
1
15
6
6
6
7
6

output:

? 1 8
? 1 8
? 1 8
? 15 8
? 2 8
? 5 8
? 7 8
? 6 8
? 5 8
? 5 8
! 5 8
? 1 10
? 1 10
? 1 10
? 19 10
? 2 10
? 6 10
? 3 10
? 4 10
? 3 10
? 3 8
! 3 12
? 1 9
? 1 9
? 1 9
? 17 9
? 2 9
? 5 9
? 3 9
? 4 9
? 3 9
? 3 7
! 3 11
? 1 8
? 1 8
? 1 8
? 15 8
? 2 8

result: