結果

問題 No.1468 Colourful Pastel
ユーザー mtwtkmanmtwtkman
提出日時 2021-04-06 19:59:31
言語 Rust
(1.77.0)
結果
AC  
実行時間 38 ms / 1,000 ms
コード長 1,573 bytes
コンパイル時間 2,017 ms
コンパイル使用メモリ 160,060 KB
実行使用メモリ 14,316 KB
最終ジャッジ日時 2023-09-02 10:55:27
合計ジャッジ時間 3,542 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
14,104 KB
testcase_01 AC 37 ms
14,100 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,388 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,384 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 28 ms
14,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: field `num` is never read
  --> Main.rs:30:5
   |
29 | struct Input {
   |        ----- field in this struct
30 |     num: usize,
   |     ^^^
   |
   = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

ソースコード

diff #

mod p1468 {
    use std::collections::BTreeMap;

    fn gather(v: Vec<String>) -> BTreeMap<String, usize> {
        v.into_iter().fold(BTreeMap::new(), |mut acc, s| {
            let count = acc.get(&s).unwrap_or(&0);
            acc.insert(s, count + 1);
            acc
        })
    }

    pub fn solve(begin: Vec<String>, after: Vec<String>) -> String {
        let begin_map = gather(begin);
        let after_map = gather(after);

        for (k, v) in begin_map.into_iter() {
            if let Some(taken) = after_map.get(&k) {
                if taken != &v {
                    return k
                }
            } else {
                return k
            }
        }
        return "--".to_string()
    }
}

struct Input {
    num: usize,
    begin: Vec<String>,
    after: Vec<String>,
}

impl Input {
    fn readline(len: usize) ->  Vec<String> {
        use std::io::{self, BufRead};

        let stdin = io::stdin();
        let lines = stdin.lock().lines().map(|l| l.unwrap().to_string());
        lines.take(len).collect()
    }

    fn accept(len: usize) -> Self {
        let lines = Self::readline(len);
        let num = lines[0].parse::<usize>().unwrap();
        let begin = lines[1].split(" ").map(|s| s.to_string()).collect::<Vec<_>>();
        let after = lines[2].split(" ").map(|s| s.to_string()).collect::<Vec<_>>();
        Self {
            num,
            begin,
            after,
        }
    }
}

fn main() {
    let args = Input::accept(3);
    let result = p1468::solve(args.begin, args.after);
    println!("{}", result);
}
0