QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#218863#6394. Turn on the Lighttherehello#WA 1ms3600kbC++20954b2023-10-18 19:29:182023-10-18 19:29:19

Judging History

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

  • [2023-10-18 19:29:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3600kb
  • [2023-10-18 19:29:18]
  • 提交

answer

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

using ll = long long;
using i64 = long long;

void solve() {
    int n;
    cin >> n;
    int l = 1, r = n;
    auto ask = [&](int x) {
        cout << "? " << x << endl;
        int ret;
        cin >> ret;
        return ret;
    };
    auto submit = [&](int x) { cout << "! " << x << endl; };
    int v = 0;
    while (l < r) {
        int mid = l + r >> 1;
        int v1 = ask(mid);
        if (v1 == v) {
            submit(mid);
            return;
        }
        int v2 = ask(l);
        if (v2 == v) {
            r = mid;
        } else if (v2 == v1) {
            submit(l);
            return;
        } else {
            l = mid + 1;
        }
        v = v2;
    }
    submit(l);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2

output:

? 2
? 1
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
2
3
4
5
5

output:

? 5
? 1
? 8
? 6
? 9
? 9
! 9

result:

wrong answer Wrong favorite light!