QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#402274#6394. Turn on the Lightiwew#WA 1ms3660kbC++20767b2024-04-30 10:43:472024-04-30 10:43:47

Judging History

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

  • [2024-04-30 10:43:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3660kb
  • [2024-04-30 10:43:47]
  • 提交

answer

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

typedef long long ll;

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

    int n;
    cin >> n;
    int l = 1, r = n, lstd = 0;

    auto ask = [&](int mid) -> int {
        cout << "? " << mid << endl;
        int d;
        cin >> d;
        return d;
    };

    int ans = -1;
    while(l < r) {
        int mid = (l + r) >> 1;
        auto curd = ask(mid);
        if(curd - lstd == 0) {
            ans = mid;
            break;
        } else if(curd - lstd == 1) {
            l = mid + 1;
        } else {
            r = mid - 1;
        }
        lstd = curd;
    }
    if(ans == -1) ans = l;
    cout << "! " << ans << endl;
    return 0;
}

详细

Test #1:

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

input:

3
1

output:

? 2
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
2
3

output:

? 5
? 8
? 9
! 10

result:

wrong answer Wrong answer, more than 1 possible light!