QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#281089#6394. Turn on the LightpiscesWA 1ms3620kbC++14984b2023-12-09 20:55:522023-12-09 20:55:52

Judging History

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

  • [2023-12-09 20:55:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3620kb
  • [2023-12-09 20:55:52]
  • 提交

answer

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
int cnt = 0;
int q(int x) {
    int last = cnt;
    cout << "? " << x << endl;
    cin >> cnt;
    if (cnt == last) {
        cout << "! " << x << endl;
        return 0;
    } else if (cnt == last - 1) {
        return 1; 
    } else if (cnt == last + 1) {
        return -1;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n; cin >> n;
    int l = 21, r = n;
    for (int i = 1; i <= 20; i++) {
        if (q(i) == 0) {
            return 0;
        }
    }
    while (1) {
        int mid = l + r >> 1;
        int qval = q(mid);
        if (qval == 0) {
            return 0;
        }
        else if (qval == 1) {
            l = mid + 1;
        }
        if (qval == -1) {
            r = mid - 1; 
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2
2

output:

? 1
? 2
? 3
! 3

result:

ok Correct position at 3

Test #2:

score: 0
Accepted
time: 1ms
memory: 3576kb

input:

10
1
2
3
4
5
6
7
8
8

output:

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

result:

ok Correct position at 9

Test #3:

score: 0
Accepted
time: 1ms
memory: 3448kb

input:

9
1
2
3
4
5
6
7
7

output:

? 1
? 2
? 3
? 4
? 5
? 6
? 7
? 8
! 8

result:

ok Correct position at 8

Test #4:

score: 0
Accepted
time: 1ms
memory: 3392kb

input:

8
1
2
3
4
5
6
6

output:

? 1
? 2
? 3
? 4
? 5
? 6
? 7
! 7

result:

ok Correct position at 7

Test #5:

score: 0
Accepted
time: 0ms
memory: 3564kb

input:

7
1
2
3
4
5
5

output:

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

result:

ok Correct position at 6

Test #6:

score: 0
Accepted
time: 0ms
memory: 3448kb

input:

6
1
2
3
4
5
5

output:

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

result:

ok Correct position at 6

Test #7:

score: 0
Accepted
time: 1ms
memory: 3340kb

input:

5
1
2
3
3

output:

? 1
? 2
? 3
? 4
! 4

result:

ok Correct position at 4

Test #8:

score: 0
Accepted
time: 1ms
memory: 3620kb

input:

4
1
2
3
3

output:

? 1
? 2
? 3
? 4
! 4

result:

ok Correct position at 4

Test #9:

score: 0
Accepted
time: 0ms
memory: 3496kb

input:

3
1
1

output:

? 1
? 2
! 2

result:

ok Correct position at 2

Test #10:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2
1
1

output:

? 1
? 2
! 2

result:

ok Correct position at 2

Test #11:

score: 0
Accepted
time: 1ms
memory: 3612kb

input:

1
0

output:

? 1
! 1

result:

ok Correct position at 1

Test #12:

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

input:

1000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
39

output:

? 1
? 2
? 3
? 4
? 5
? 6
? 7
? 8
? 9
? 10
? 11
? 12
? 13
? 14
? 15
? 16
? 17
? 18
? 19
? 20
? 500010
? 250015
? 125017
? 62518
? 31269
? 15644
? 7832
? 3926
? 1973
? 996
? 508
? 264
? 142
? 81
? 50
? 35
? 27
? 23
? 21
? 20
! 20

result:

wrong answer Wrong answer, more than 1 possible light!