結果

問題 No.806 木を道に
ユーザー iwotiwot
提出日時 2019-08-13 23:29:15
言語 Rust
(1.77.0)
結果
WA  
実行時間 -
コード長 990 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 187,360 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 17:17:56
合計ジャッジ時間 3,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 6 ms
4,348 KB
testcase_12 WA -
testcase_13 AC 19 ms
4,348 KB
testcase_14 AC 24 ms
4,348 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 22 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 28 ms
4,348 KB
testcase_24 AC 14 ms
4,348 KB
testcase_25 AC 22 ms
4,348 KB
testcase_26 AC 9 ms
4,348 KB
testcase_27 AC 26 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let peak_max: usize = read();

    let mut peaks = HashMap::new();
    loop {
        let input: Vec<u32> = read_vec();
        {
            let e = peaks.entry(input[0]).or_insert(0);
            *e += 1;
        }
        {
            let e = peaks.entry(input[1]).or_insert(0);
            *e += 1;
        }
        if peaks.len() >= peak_max {
            break;
        }
    }

    let mut operation = 0;
    for (_peak, count) in &peaks {
        if *count > 2 {
            operation += *count - 2;
        }
    }

    println!("{}", operation);
}
0