QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614052#8239. Mysterious Treeklhwong#WA 1ms3544kbC++172.6kb2024-10-05 15:29:252024-10-05 15:29:25

Judging History

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

  • [2024-10-05 15:29:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3544kb
  • [2024-10-05 15:29:25]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

int t, n, res, u, v, x, y;
bool flag;
string q;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    cin >> t;
    
    while(t--) {
        cin >> n;
        flag = false;

        for (int i = 1; i <= n; i += 2) {
            q = "? " + to_string(i) + " " + to_string(i + 1) + "\n";
            cout << q;
            cout.flush();

            cin >> res;

            if (res == 1) {
                u = i;
                v = i + 1;
                if (i == 1) {
                    x = n - 1;
                    y = n;
                } else {
                    x = 1;
                    y = 2;
                }
                flag = true;
                break;
            }
        }

        if (!flag && n % 2 == 1) {
            q = "? " + to_string(n - 1) + " " + to_string(n) + "\n";
            cout << q;
            cout.flush();
            cin >> res;

            if (res == 1) {
                u = n - 1;
                v = n;
                x = 1;
                y = 2;
                flag = true;
            }
        }

        if (!flag) {
            cout << "! 2" << "\n";
            cout.flush();
        } else {
            q = "? " + to_string(u) + " " + to_string(x) + "\n";
            cout << q;
            cout.flush();
            cin >> res;
            if (res == 0) {
                q = "? " + to_string(v) + " " + to_string(x) + "\n";
                cout << q;
                cout.flush();
                cin >> res;
                if (res == 0) {
                    cout << "! 1" << "\n";
                    cout.flush();
                } else {
                    q = "? " + to_string(v) + " " + to_string(y) + "\n";
                    cout << q;
                    cout.flush();
                    cin >> res;

                    if (res == 1) {
                        cout << "! 2" << "\n";
                        cout.flush();
                    } else {
                        cout << "! 1" << "\n";
                        cout.flush();
                    }
                }
            } else {
                q = "? " + to_string(u) + " " + to_string(y) + "\n";
                cout << q;
                cout.flush();
                cin >> res;
                if (res == 0) {
                    cout << "! 1" << "\n";
                    cout.flush();
                } else {
                    cout << "! 2" << "\n";
                    cout.flush();
                }
            }
        }
    }

    cout.flush();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4
1
0
1
0
4
0
1
1
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3500kb

input:

87
13
0
0
0
0
0
1
0
1
1
15
0
0
0
0
0
0
1
1
1
7
0
0
0

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 11 1
? 12 1
? 12 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 13 1
? 13 2
! 2
? 1 2
? 3 4
? 5 6
? 7 8

result:

wrong answer Integer 8 violates the range [1, 7] (test case 3)