QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#647887#8239. Mysterious Treeyixuanoct#WA 3ms3648kbC++202.9kb2024-10-17 16:03:362024-10-17 16:03:37

Judging History

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

  • [2024-10-17 16:03:37]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3648kb
  • [2024-10-17 16:03:36]
  • 提交

answer

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

#define int long long

const int N = 1e6 + 7;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve() {
    int n, x, y, z;
    cin >> n;
    int cnt = 0, a = 0, b = 0;
    for (int i = 1;i < n;i += 2) {
        cout << "? " << i << ' ' << i + 1 << endl;
        cin >> x;
        if (x == 1) {
            cnt++;
            a = i;
            b = i + 1;
        }
    }
    if (n & 1) {
        if (cnt == 0) {
            cout << "? " << n << ' ' << 1 << endl;
            cin >> x;
            cout << "? " << n << ' ' << 2 << endl;
            cin >> y;
            cout << "? " << n << ' ' << 3 << endl;
            cin >> z;
            if (x == 1 && y == 1 && z == 1) cout << "! 2" << endl;
            else cout << "! 1" << endl;
        }
        else if (cnt == 1) {
            int a1 = (a == n - 2 ? 1 : a + 2);
            int a2 = (a1 == n - 2 ? 1 : a1 + 2);
            int b1 = (b == n - 1 ? 2 : b + 2);
            int b2 = (b1 == n - 1 ? 2 : b1 + 2);
            cout << "? " << a << ' ' << b1 << endl;
            cin >> x;
            cout << "? " << a1 << ' ' << b << endl;
            cin >> y;
            if (x == y) cout << "! 1" << endl;
            else {
                if (x == 1) {
                    cout << "? " << a << ' ' << b2 << endl;
                    cin >> x;
                    if (x == 1) cout << "! 2" << endl;
                    else cout << "! 1" << endl;
                }
                else {
                    cout << "? " << a2 << ' ' << b << endl;
                    cin >> x;
                    if (x == 1) cout << "! 2" << endl;
                    else cout << "! 1" << endl;
                }
            }
        }
        else cout << "! 1" << endl;
    }
    else {
        if (cnt == 1) {
            int a1 = (a == n - 1 ? 1 : a + 2);
            int a2 = (a1 == n - 1 ? 1 : a1 + 2);
            int b1 = (b == n ? 2 : b + 2);
            int b2 = (b1 == n ? 2 : b1 + 2);
            cout << "? " << a << ' ' << b1 << endl;
            cin >> x;
            cout << "? " << a1 << ' ' << b << endl;
            cin >> y;
            if (x == y) cout << "! 1" << endl;
            else {
                if (x == 1) {
                    cout << "? " << a << ' ' << b2 << endl;
                    cin >> x;
                    if (x == 1) cout << "! 2" << endl;
                    else cout << "! 1" << endl;
                }
                else {
                    cout << "? " << a2 << ' ' << b << endl;
                    cin >> x;
                    if (x == 1) cout << "! 2" << endl;
                    else cout << "! 1" << endl;
                }
            }
        }
        else cout << "! 1" << endl;
    }
}

signed main() {
    // ios::sync_with_stdio(false), cin.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3636kb

input:

2
4
1
1
4
0
1
1
0
1

output:

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

result:

ok Correct (2 test cases)

Test #2:

score: 0
Accepted
time: 3ms
memory: 3632kb

input:

87
13
0
0
0
0
0
1
0
1
1
15
0
0
0
0
0
0
1
1
0
1
7
0
0
0
1
1
1
15
0
0
0
1
1
0
0
19
0
0
0
0
0
1
0
0
0
1
0
1
20
0
0
0
0
0
0
0
0
0
0
7
0
0
1
0
1
1
20
0
0
0
0
0
0
0
1
0
0
1
0
1
17
0
0
0
0
0
0
0
0
0
0
1
11
1
1
0
0
0
14
0
0
0
0
0
0
0
13
0
0
0
0
0
0
0
0
0
18
0
0
0
0
0
1
0
0
0
0
1
1
14
0
1
0
0
0
0
0
0
1
1
20
...

output:

? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 11 2
? 1 12
? 3 12
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 13 2
? 1 14
? 13 4
! 2
? 1 2
? 3 4
? 5 6
? 7 1
? 7 2
? 7 3
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
! 1
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 11 12
? 13 14
? 15 16
? 17 18
? 11 14
? ...

result:

ok Correct (87 test cases)

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3648kb

input:

135
9
1
0
1
1
6
0
0
0
11
0
0
0
0
1
0
0
4
1
1
10
0
0
0
0
1
1
0
1
9
0
0
0
1
1
0
1
9
0
0
1
0
0
1
1
6
0
0
0
9
0
0
0
1
1
0
1
11
0
0
0
0
1
0
0
4
0
0
4
1
0
1
0
1
8
0
0
0
0
5
0
0
0
0
0
7
1
0
0
0
0
11
0
0
0
0
1
0
1
1
4
1
0
1
0
1
6
1
0
0
1
0
1
9
0
0
1
0
1
0
1
4
1
0
0
1
1
8
1
0
1
0
9
0
0
1
0
0
1
1
7
0
0
1
0
0
...

output:

? 1 2
? 3 4
? 5 6
? 7 8
! 1
? 1 2
? 3 4
? 5 6
! 1
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 9 2
? 1 10
! 1
? 1 2
? 3 4
! 1
? 1 2
? 3 4
? 5 6
? 7 8
? 9 10
? 9 2
? 1 10
? 9 4
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 7 2
? 1 8
? 7 4
! 2
? 1 2
? 3 4
? 5 6
? 7 8
? 5 8
? 7 6
? 1 6
! 2
? 1 2
? 3 4
? 5 6
! 1
? 1 2
? 3 4
? 5 6
...

result:

wrong answer Wrong prediction (test case 45)