QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#384019#6394. Turn on the LightdreamwaveWA 1ms3652kbC++14992b2024-04-09 20:01:482024-04-09 20:01:48

Judging History

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

  • [2024-04-09 20:01:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3652kb
  • [2024-04-09 20:01:48]
  • 提交

answer

#include <bits/stdc++.h>

void solve() {
    int n;
    std::cin >> n;
    auto dfs = [&](auto self, int l, int r, int v) -> void {
        if(l == r) {
            std::cout << "! " << l << std::endl;
            exit(0);
        }
        int mid = (l + r) >> 1;
        std::cout << "? " << l << std::endl;
        int val;
        std::cin >> val;
        if(val == v) {
            std::cout << "! " << l << std::endl;
            exit(0);
        }
        std::cout << "? " << mid << std::endl;
        int val2;
        std::cin >> val2;
        if(val == val2) {
            std::cout << "! " << mid << std::endl;
            exit(0);
        }
        if(val + 1 == val2) {
            self(self, mid + 1, r, val2);
        } else {
            self(self, l + 1, mid - 1, val2);
        }
    } ;
    dfs(dfs, 1, n, 0);
}

int main() {
    std::cin.tie(nullptr) -> sync_with_stdio(false);
    int T = 1;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
2

output:

? 1
? 2
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
2
3
4
5
5

output:

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

result:

wrong answer Wrong favorite light!