QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581814#8239. Mysterious Tree333zhanWA 0ms3568kbC++201.4kb2024-09-22 14:15:542024-09-22 14:16:02

Judging History

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

  • [2024-09-22 14:16:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3568kb
  • [2024-09-22 14:15:54]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

int ask (int x, int y) {
    cout << "? " << x << " " << y << endl;

    int ans;
    cin >> ans;
    return ans;
}

void solve () {
    int n;
    cin >> n;

    int ax = -1, ay;
    for (int i = 1; i <= (n + 1) / 2; i += 2) {
        int x = i;
        int y = n & 1 && i == n ? 1 : i + 1;
        if (ask (x, y)) {
            ax = x;
            ay = y;
            break;
        }
    }

    if (ax == -1) {
        cout << "! 1" << endl;
        return;
    }

    int az;
    int ans1, ans2;
    vector <bool> ok (n + 1);
    for (int i = 1; i <= n; i ++) {
        if (i != ax && i != ay) {
            ans1 = ask (ax, i);
            ans2 = ask (ay, i);
            az = i;
            if (! ans1 && ! ans2) {
                cout << "! 1" << endl;
                return;
            } else {
                break;
            }
        }
    }

    for (int i = 1; i <= n; i ++) {
        if (i != ax && i != ay && i != az) {
            if (ask (ans1 ? ax : ay, i)) {
                cout << "! 2" << endl;
            } else {
                cout << "! 1" << endl;
            }
            return;
        }
    }
}

signed main () {
    ios::sync_with_stdio (false);
    cin.tie (nullptr);

    int T = 1;
    cin >> T;

    while (T --) {
        solve ();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1
0
1
0
4
0

output:

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

result:

wrong answer Wrong prediction (test case 2)