結果

問題 No.3212 SUPER Guess the Number
ユーザー akakimidori
提出日時 2025-07-25 22:20:07
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 865 bytes
コンパイル時間 13,866 ms
コンパイル使用メモリ 396,768 KB
実行使用メモリ 25,984 KB
平均クエリ数 23.92
最終ジャッジ日時 2025-07-25 22:20:24
合計ジャッジ時間 14,988 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

// 

fn main() {
    let mut cnt = 0;
    let mut query = |x: i32| -> i32 {
        assert!(x.abs() <= 1_000_000_000);
        assert!(cnt < 25);
        cnt += 1;
        println!("? {x}");
        if cnt > 1 {
            let v = read();
            assert!(v != -1);
            v
        } else {
            0
        }
    };
    let mut l = 1;
    let mut r = 1000000;
    let mut pre = l;
    query(l);
    while l + 2 <= r {
        let m = (l + r) / 2;
        let x = 2 * m - pre;
        let res = query(x);
        if (res == 1) ^ (pre <= m) {
            r = m;
        } else {
            l = m;
        }
        pre = x;
    }
    query(l);
    let ans = if query(r) == 1 {r} else {l};
    println!("! {}", ans);
}

fn read() -> i32 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().unwrap()
}
0