結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 7 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 3 ms
4,348 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 29 ms
4,348 KB
testcase_24 AC 13 ms
4,348 KB
testcase_25 AC 22 ms
4,348 KB
testcase_26 AC 8 ms
4,348 KB
testcase_27 AC 26 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unnecessary parentheses around assigned value
  --> Main.rs:36:26
   |
36 |             operation += (*count - 2);
   |                          ^          ^
   |
   = note: `#[warn(unused_parens)]` on by default
help: remove these parentheses
   |
36 -             operation += (*count - 2);
36 +             operation += *count - 2;
   |

warning: unused variable: `peak`
  --> Main.rs:34:10
   |
34 |     for (peak, count) in &peaks {
   |          ^^^^ help: if this is intentional, prefix it with an underscore: `_peak`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: 2 warnings emitted

ソースコード

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