QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#221745#6394. Turn on the Lighttselmegkh#WA 1ms3584kbC++17939b2023-10-21 14:27:162023-10-21 14:27:16

Judging History

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

  • [2023-10-21 14:27:16]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2023-10-21 14:27:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int qry(int x) {
    cout << "? " << x + 1 << endl;
    int a;
    cin >> a;
    return a;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    set<int> off;
    for (int i = 0; i < n; i++) {
        off.insert(i);
    }
    int dif = 0, lo = 0, hi = n - 1;
    while (lo < hi) {
        int d = qry(*off.begin());
        if (d == dif) {
            cout << "! " << *off.begin() + 1 << endl;
            return 0;
        }
        off.erase(off.begin());
        dif = d;
        int mi = (lo + hi) / 2;
        d = qry(mi);
        if (d == dif) {
            cout << "! " << mi + 1 << endl;
            return 0;
        }
        if (d > dif) {
            lo = mi + 1;
        } else {
            hi = mi - 1;
        }
        dif = d;
        off.erase(mi);
    }
    cout << "! " << lo << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3584kb

input:

3
1
2

output:

? 1
? 2
! 2

result:

wrong answer Wrong favorite light!