QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#857221#9734. Identify ChordpropaneWA 0ms3712kbC++202.8kb2025-01-15 13:04:262025-01-15 13:04:27

Judging History

你现在查看的是最新测评结果

  • [2025-01-15 13:04:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3712kb
  • [2025-01-15 13:04:26]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<cassert>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;

        auto dis = [&](int a, int b){
            int d = (b - a + n) % n;
            d = min(d, n - d);
            return d;
        };

        auto ask = [&](int x, int y){
            cout << "? " << x + 1 << ' ' << y + 1 << endl;
        
            #ifdef LOCAL
                int p[2]{100, 102};
                int ans = dis(x, y);
                for(int i = 0; i < 2; i++){
                    for(int j = 0; j < 2; j++){
                        ans = min(ans, 1 + dis(x, p[i]) + dis(y, p[j]));
                    }
                }
                return ans;
            #endif
            int t;
            cin >> t;
            return t;
        };

        if (n <= 10){
            bool ok = false;
            for(int i = 0; i < n and !ok; i++){
                for(int j = i + 1; j < n and !ok; j++){
                    if (dis(i, j) != 1 and ask(i, j) == 1){
                        ok = true;
                        cout << "! " << i + 1 << ' ' << j + 1 << endl;
                    }
                }
            }
            continue;
        }
        int best = 1e9;
        int p1 = -1, p2 = -1;
        for(int i = 0, st = 0; i < 4; i++, st += n / 8){
            p1 = st, p2 = st + n / 2;
            int t = ask(p1, p2);
            if (t < best){
                best = t;
            }
        }
        int ans1 = -1, ans2 = -1;
        if (ask((p1 + 1) % n, p2) == best - 1){
            int l = 0, r = best - 1;
            while(l < r){
                int mid = (l + r + 1) / 2;
                if (ask((p1 + mid) % n, p2) == best - mid) l = mid;
                else r = mid - 1;
            }
            ans1 = (p1 + r) % n;
        }
        else{
            int l = 0, r = best - 1;
            while(l < r){
                int mid = (l + r + 1) / 2;
                if (ask((p1 - mid + n) % n, p2) == best - mid) l = mid;
                else r = mid - 1;
            }
            ans1 = (p1 - r + n) % n;
        }
        int d = dis(ans1, p1);
        int remain = best - d - 1;
        int cand1 = (p2 - remain + n) % n;
        int cand2 = (p2 + remain) % n;
        if (dis(ans1, cand1) > 1 and ask(ans1, cand1) == 1){
            ans2 = cand1;
        }
        else{
            ans2 = cand2;
        }
        cout << "! " << ans1 + 1 << ' ' << ans2 + 1 << endl;
        int t;
        cin >> t;
    }

}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

2
6
2
2
2
1
1
4

output:

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

result:

wrong answer format  Unexpected end of file - token expected (test case 2)