QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#548355#6394. Turn on the Lightpandapythoner#WA 0ms3660kbC++231.2kb2024-09-05 17:25:422024-09-05 17:25:43

Judging History

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

  • [2024-09-05 17:25:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3660kb
  • [2024-09-05 17:25:42]
  • 提交

answer

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

using ll = long long;
using ld = long double;

#define len(a) int((a).size())
#define all(a) begin(a), end(a)
#define rep(i, n) for (int i = 0; i < (n); i++)

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);

    int n;
    cin >> n;

#ifdef LOCAL
    int x = rand() % n;
    cerr << "x=" << x << endl;
    int cur_ans_ = 0;
#endif

    auto query = [&](int pos) {
        cout << "? " << pos << endl;
#ifdef LOCAL
        if (pos < x) {
            cur_ans_++;
        } else if (pos > x) {
            cur_ans_--;
        }
        return cur_ans_;
#else
        int res;
        cin >> res;
        return res;
#endif
        };

    int prev = 0;
    int l = 0, r = n;
    while (true) {
        int mid = (l + r) / 2;
        int cur = query(mid);
        if (cur == prev) {
            cout << "! " << mid + 1 << endl;
#ifdef LOCAL
            assert(mid == x);
#endif
            return 0;
        }

        assert(r - l > 1);
        if (cur > prev) {
            l = mid;
        } else {
            r = mid;
        }
        prev = cur;
    }
}

詳細信息

Test #1:

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

input:

3
1
2
2

output:

? 1
? 2
? 2
! 3

result:

ok Correct position at 3

Test #2:

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

input:

10
1
2
3
4
4

output:

? 5
? 7
? 8
? 9
? 9
! 10

result:

wrong answer Wrong answer, more than 1 possible light!