結果

問題 No.2252 Find Zero
ユーザー haihamabossuhaihamabossu
提出日時 2023-03-24 21:46:09
言語 Rust
(1.77.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 5,046 ms
コンパイル使用メモリ 159,200 KB
実行使用メモリ 24,624 KB
平均クエリ数 78.17
最終ジャッジ日時 2023-10-18 20:56:39
合計ジャッジ時間 7,344 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
24,624 KB
testcase_01 AC 75 ms
24,624 KB
testcase_02 AC 55 ms
24,624 KB
testcase_03 AC 65 ms
24,624 KB
testcase_04 AC 57 ms
24,624 KB
testcase_05 AC 56 ms
24,624 KB
testcase_06 AC 55 ms
24,624 KB
testcase_07 AC 55 ms
24,624 KB
testcase_08 AC 62 ms
24,624 KB
testcase_09 AC 67 ms
24,624 KB
testcase_10 AC 54 ms
24,624 KB
testcase_11 AC 54 ms
24,624 KB
testcase_12 AC 55 ms
24,624 KB
testcase_13 AC 53 ms
24,624 KB
testcase_14 AC 55 ms
24,624 KB
testcase_15 AC 52 ms
24,624 KB
testcase_16 AC 56 ms
24,624 KB
testcase_17 AC 54 ms
24,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Write;

fn query(x: usize, y: usize) -> usize {
    println!("? {} {}", x, y);
    std::io::stdout().flush().unwrap();
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).ok();
    let mut input = input.split_whitespace();
    input.next().unwrap().parse().unwrap()
}

fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).ok();
    let mut input = input.split_whitespace();
    let n: usize = input.next().unwrap().parse().unwrap();
    for i in 0..(n / 2) {
        let x = i * 2;
        let y = x + 1;
        let z = query(x, y);
        if z == x {
            println!("! {}", y);
            return;
        } else if z == y {
            println!("! {}", x);
            return;
        }
    }
    println!("! {}", n - 1);
}
0