結果

問題 No.1830 Balanced Majority
ユーザー phsplsphspls
提出日時 2022-10-18 21:24:49
言語 Rust
(1.77.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 3,480 ms
コンパイル使用メモリ 139,896 KB
実行使用メモリ 24,336 KB
平均クエリ数 7.69
最終ジャッジ日時 2023-09-11 13:36:43
合計ジャッジ時間 9,873 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
24,024 KB
testcase_01 AC 23 ms
23,652 KB
testcase_02 AC 23 ms
23,628 KB
testcase_03 AC 23 ms
24,120 KB
testcase_04 AC 22 ms
24,024 KB
testcase_05 AC 23 ms
24,036 KB
testcase_06 AC 23 ms
24,036 KB
testcase_07 AC 24 ms
23,532 KB
testcase_08 AC 23 ms
23,664 KB
testcase_09 AC 24 ms
23,628 KB
testcase_10 AC 24 ms
23,832 KB
testcase_11 AC 25 ms
24,336 KB
testcase_12 AC 25 ms
23,640 KB
testcase_13 AC 24 ms
24,312 KB
testcase_14 AC 25 ms
24,024 KB
testcase_15 AC 25 ms
23,652 KB
testcase_16 AC 25 ms
23,628 KB
testcase_17 AC 26 ms
24,264 KB
testcase_18 AC 24 ms
23,820 KB
testcase_19 AC 24 ms
23,652 KB
testcase_20 AC 24 ms
23,520 KB
testcase_21 AC 25 ms
23,400 KB
testcase_22 AC 26 ms
24,312 KB
testcase_23 AC 26 ms
23,364 KB
testcase_24 AC 25 ms
23,364 KB
testcase_25 AC 23 ms
24,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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