QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#574747#6394. Turn on the LightGammaRaysWA 1ms3728kbC++231006b2024-09-19 00:14:422024-09-19 00:14:44

Judging History

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

  • [2024-09-19 00:14:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3728kb
  • [2024-09-19 00:14:42]
  • 提交

answer

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

void answer(int x) {
    cout << '!' << ' ' << x << endl;
    exit(0);
}

int ask(int x) {
    cout << '?' << ' ' << x << endl;
    int ret;
    cin >> ret;
    return ret;
}
int n;
int L = 1;
int R = n;
int LST = 0;

void solve(int l, int r, int lst) {
    L = l;
    R = r;
    LST = lst;
    if (l + 1 < r) {

    } else {
        return;
    }
    int x = ask(r);
    if(x == lst) {
        answer(r);
    }
    r --;
    int mid = (l + r) >> 1;
    int y = ask(mid);
    if(y == x) {
        answer(mid);
    }
    if(x < y) {
        solve(l, mid - 1, y);
    }
    //0 1 1
    else {
        solve(mid + 1, r - 1, y);
    }
    return;
}

int main() {
    cin >> n;
    L = 1, R = n;
    solve(1, n, 0);
    // cout << L << ' ' << R << endl;
    int res = ask(L);
    if (res == LST) {
        answer(L);
    } 
    LST = res;
    if (ask(R) == LST){
        answer(R);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
0

output:

? 3
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
0
1
0
0

output:

? 10
? 5
? 8
? 6
? 7
! 7

result:

ok Correct position at 7

Test #3:

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

input:

9
1
0
1
0
0

output:

? 9
? 4
? 7
? 5
? 6
! 6

result:

ok Correct position at 6

Test #4:

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

input:

8
1
0
1
1

output:

? 8
? 4
? 5
? 6
! 6

result:

ok Correct position at 6

Test #5:

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

input:

7
1
0
1
1

output:

? 7
? 3
? 4
? 5
! 5

result:

ok Correct position at 5

Test #6:

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

input:

6
1
0
1
1

output:

? 6
? 3
? 4
? 4
! 4

result:

wrong answer Wrong favorite light!