結果

問題 No.1830 Balanced Majority
ユーザー phsplsphspls
提出日時 2022-10-12 00:48:45
言語 Rust
(1.77.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,252 bytes
コンパイル時間 1,126 ms
コンパイル使用メモリ 139,644 KB
実行使用メモリ 24,300 KB
平均クエリ数 7.54
最終ジャッジ日時 2023-09-08 02:14:53
合計ジャッジ時間 4,294 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,796 KB
testcase_01 AC 23 ms
23,412 KB
testcase_02 AC 22 ms
23,688 KB
testcase_03 AC 23 ms
23,592 KB
testcase_04 AC 23 ms
24,060 KB
testcase_05 AC 23 ms
23,448 KB
testcase_06 AC 23 ms
23,448 KB
testcase_07 AC 24 ms
23,340 KB
testcase_08 AC 24 ms
23,580 KB
testcase_09 AC 24 ms
23,856 KB
testcase_10 AC 24 ms
23,496 KB
testcase_11 AC 25 ms
23,796 KB
testcase_12 AC 25 ms
23,496 KB
testcase_13 AC 26 ms
24,012 KB
testcase_14 AC 26 ms
23,568 KB
testcase_15 AC 25 ms
23,436 KB
testcase_16 AC 26 ms
24,300 KB
testcase_17 AC 25 ms
24,072 KB
testcase_18 AC 25 ms
23,664 KB
testcase_19 AC 22 ms
23,568 KB
testcase_20 AC 23 ms
23,196 KB
testcase_21 AC 26 ms
24,300 KB
testcase_22 AC 25 ms
23,976 KB
testcase_23 AC 26 ms
24,096 KB
testcase_24 AC 27 ms
23,508 KB
testcase_25 AC 23 ms
23,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: isize = n.trim().parse().unwrap();

    let mut upper = n-1;
    let mut lower = 1isize;
    println!("? {}", lower);
    let mut sl = String::new();
    std::io::stdin().read_line(&mut sl).ok();
    let sl: isize = sl.trim().parse().unwrap();
    let sl = sl * 2 - 1;
    println!("? {}", upper);
    let mut sr = String::new();
    std::io::stdin().read_line(&mut sr).ok();
    let sr: isize = sr.trim().parse().unwrap();
    let sr = sr * 2 - (n - 1);
    if sl == sr {
        println!("! {} {}", lower+1, upper);
        return;
    }
    let pm = -sl;
    while lower < upper {
        let middle = (upper + lower) / 2;
        println!("? {}", middle);
        let mut sl = String::new();
        std::io::stdin().read_line(&mut sl).ok();
        let sl: isize = sl.trim().parse().unwrap();
        let sl = sl * 2 - middle;
        if sl == 0 {
            lower = middle;
            upper = middle;
        } else if sl * pm < 0 {
            lower = middle;
        } else {
            upper = middle;
        }
    }
    if lower >= n/2 {
        println!("! {} {}", 1, lower);
    } else {
        println!("! {} {}", lower+1, n);
    }
}
0