結果

問題 No.3212 SUPER Guess the Number
コンテスト
ユーザー rieaaddlreiuu
提出日時 2026-05-14 20:04:05
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 923 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,696 ms
コンパイル使用メモリ 179,668 KB
実行使用メモリ 30,308 KB
平均クエリ数 22.00
最終ジャッジ日時 2026-05-14 20:04:15
合計ジャッジ時間 4,275 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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

int main() {
    int L = 1, R = 1000000;

    long long prev = 1;
    cout << "? " << prev << endl;
    cout.flush();

    while (L < R) {
        int mid = (L + R) / 2;

        // 判定したいこと:
        // a >= mid + 1 かどうか
        //
        // |a - prev| >= |a - x| が成り立つ境界を
        // (prev + x) / 2 = mid + 0.5
        // にしたいので、
        // x = 2 * mid + 1 - prev
        long long x = 2LL * mid + 1 - prev;

        cout << "? " << x << endl;
        cout.flush();

        int res;
        cin >> res;

        if (res == -1) return 0;

        if (res == 1) {
            // |a-prev| >= |a-x|
            // つまり a >= mid + 1
            L = mid + 1;
        } else {
            // a <= mid
            R = mid;
        }

        prev = x;
    }

    cout << "! " << L << endl;
    cout.flush();

    return 0;
}
0