QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#528306#6394. Turn on the LightOneWan#WA 1ms3720kbC++231.5kb2024-08-23 12:38:212024-08-23 12:38:21

Judging History

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

  • [2024-08-23 12:38:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3720kb
  • [2024-08-23 12:38:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int query(int x) {
    cout << "? " << x << endl;
    cin >> x;
    return x;
}
void ans(int x) {
    cout << "! " << x << endl;
    exit(0);
}
int main() {

    int n;
    cin >> n;

    int x = query(1);
    if (x == 0) {
        ans(1);
    } else {
        int L = 2, R = n, last = x;
        while (L < R) {
            int mid = L + R >> 1;
            x = query(mid);
            if (x == last) {
                ans(mid);
            }
            if (x == 0) {
                x = query(L);
                L++;
                R = mid - 1;
                last = x;
                continue;
            }
            if (last > x) {
                R = mid - 1;
            } else {
                L = mid + 1;
            }
            last = x;
        }
        ans(L);
    }
    // for (int i = 1; i <= min(20, n); i++) {
    //     int x = query(i);
         
    //     if(x != i) {
    //         ans(i);
    //     }
    // }
    // cout << '\n';
    // {
    //     int L = 20, R = n;
    //     int last = x;
    //     while (L + 1 < R) {
    //         int mid = L + R + 1 >> 1;
    //         x = query(mid);
    //         cout << x << '\n';
    //         if (x == last) {
    //             ans(mid);
    //         }
    //         else if (x > last) {
    //             L = mid;
    //         } else {
    //             R = mid - 1; 
    //         }
    //     }
    //     ans(L + 1);
    // }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2

output:

? 1
? 2
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
0
1
0
0

output:

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

result:

wrong answer Wrong favorite light!