結果

問題 No.586 ダブルブッキング
ユーザー atuk721atuk721
提出日時 2017-11-06 03:45:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 14,663 ms
コンパイル使用メモリ 378,404 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-03 05:39:29
合計ジャッジ時間 14,913 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: field `count` is never read
  --> src/main.rs:11:5
   |
8  | struct Input {
   |        ----- field in this struct
...
11 |     count: u32,
   |     ^^^^^
   |
   = note: `Input` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
   = note: `#[warn(dead_code)]` on by default

ソースコード

diff #

use std::io;
use std::io::BufRead;
use std::io::Lines;
use std::io::StdinLock;
use std::collections::HashMap;

#[derive(Debug)]
struct Input {
    yuki_hotel_fee: u32,
    other_hotel_fee: u32,
    count: u32,
    reservations: Vec<u32>
}

fn read_next(iter: &mut Lines<StdinLock>) -> Option<u32> {
    match iter.next() {
        Some(res) => Some(res.unwrap().parse().unwrap()),
        None => None
    }
}

fn create_input() -> Input {
    let mut reservations = Vec::new();
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let yuki_fee = read_next(&mut lines).unwrap();
    let other_fee = read_next(&mut lines).unwrap();
    let count = read_next(&mut lines).unwrap();

    while let Some(data) = read_next(&mut lines) {
        reservations.push(data);
    }
    Input {yuki_hotel_fee: yuki_fee, other_hotel_fee: other_fee, count: count, reservations: reservations}
}

fn calcurate(input: &Input) -> u32 {
    let res = input.reservations.iter().fold((0, HashMap::new()), |mut acc, x| {
        if acc.1.contains_key(x) {
            let value = acc.1.get_mut(x).unwrap();
            *value += 1;
            acc.0 += 1;
        } else {
            acc.1.insert(x, 1);
        }
        acc
    });
    (input.yuki_hotel_fee + input.other_hotel_fee) * res.0
}

fn main() {
    let input = create_input();
    let result = calcurate(&input);
    println!("{}", result);
}
0