QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#614034#8239. Mysterious Treeklhwong#TL 0ms0kbC++172.2kb2024-10-05 15:23:582024-10-05 15:24:13

Judging History

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

  • [2024-10-05 15:24:13]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-10-05 15:23:58]
  • 提交

answer

#include <bits/stdc++.h>
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;

            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;
            cin >> res;

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

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

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

    cout.flush();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
4

output:


result: