結果

問題 No.3212 SUPER Guess the Number
ユーザー GOTKAKO
提出日時 2025-07-25 21:47:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,049 bytes
コンパイル時間 1,832 ms
コンパイル使用メモリ 195,380 KB
実行使用メモリ 25,972 KB
平均クエリ数 22.00
最終ジャッジ日時 2025-07-25 21:47:37
合計ジャッジ時間 3,203 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int a = 123;
    int back = -1001001001;
    int low = 0,high = 1000000;
    auto ask = [&](int x) -> void {
        cout << "? " << x << endl;
        if(back != -1001001001){
            int memo = x;
            int near; 
            near = abs(a-back)>=abs(a-x);
            cin >> near;
            if(near == 0) swap(back,x);
            int start = -1;
            for(int p=low; p<=high; p++){
                if(abs(p-x) <= abs(p-back)){
                    if(start == -1) start = p;
                }
                else if(start != -1){high = p-1; break;}
            }
            low = start;
            back = memo;
        }
        else back = x;
    };
    ask(high);

    while(low != high){
        if(high <= back){
            int d = back-high;
            ask(low-d);
        }
        else{
            int d = low-back;
            ask(high+d);
        }
    }

    cout << "! " << low << endl;
}
0