QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#548362#6394. Turn on the Lightpandapythoner#WA 1ms3668kbC++231.6kb2024-09-05 17:32:042024-09-05 17:32:04

Judging History

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

  • [2024-09-05 17:32:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3668kb
  • [2024-09-05 17:32:04]
  • 提交

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 + 1 << endl;
#ifdef LOCAL
        if (pos < x) {
            cur_ans_++;
        } else if (pos > x) {
            cur_ans_--;
        }
        return abs(cur_ans_);
#else
        int res;
        cin >> res;
        return res;
#endif
        };

    int q0 = query(0);
    if (q0 == 0) {
        cout << "! 1" << endl;
        return 0;
    }
    int q1 = query(1);
    if (q1 == q0) {
        cout << "! 2" << endl;
        return 0;
    }
    assert(q1 == 2);

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

        assert(r - l > 1);
        if (cur == 1) {
            r = mid;
            int tmp = query(0);
            assert(tmp == 2);
        } else {
            assert(cur == 3);
            l = mid;
            int tmp = query(n - 1);
            if (tmp == 3) {
                cout << "! " << n << endl;
                return 0;
            }
            assert(tmp == 2);
        }
    }
}

詳細信息

Test #1:

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

input:

3
1
2
2

output:

? 1
? 2
? 2
! 2

result:

wrong answer Wrong favorite light!