結果

問題 No.938 賢人を探せ
ユーザー phsplsphspls
提出日時 2020-01-18 00:48:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 1,412 ms
コンパイル使用メモリ 161,548 KB
実行使用メモリ 8,920 KB
最終ジャッジ日時 2023-08-21 03:43:31
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
8,920 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 18 ms
7,108 KB
testcase_09 AC 15 ms
5,628 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 21 ms
7,156 KB
testcase_12 AC 16 ms
5,680 KB
testcase_13 AC 17 ms
5,400 KB
testcase_14 AC 16 ms
5,424 KB
testcase_15 AC 16 ms
5,424 KB
testcase_16 AC 17 ms
5,348 KB
testcase_17 AC 17 ms
5,672 KB
testcase_18 AC 17 ms
5,400 KB
testcase_19 AC 16 ms
5,676 KB
testcase_20 AC 16 ms
5,388 KB
testcase_21 AC 16 ms
5,352 KB
testcase_22 AC 52 ms
8,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;
use std::collections::{HashSet, HashMap};

fn solve(ers: HashSet<String>, ees: HashSet<String>, ee_map: HashMap<String, usize>) {
    let mut result: Vec<(String, usize)> = ees.difference(&ers)
        .map(|name| (name.to_owned(), *(ee_map.get(name).unwrap())))
        .collect();
    result.sort_by_key(|r| r.1);
    result.iter().for_each(|pair| {
        println!("{}", pair.0);
    });
}

fn main() {
    let mut all_data = String::new();
    std::io::stdin().read_to_string(&mut all_data).ok();
    let all_data: Vec<&str> = all_data.trim().split('\n').map(|l| l.trim()).collect();
    let n: usize = all_data.iter().next().unwrap().parse::<usize>().unwrap();
    let mut ers: HashSet<String> = HashSet::new();
    let mut ees: HashSet<String> = HashSet::new();
    let mut ee_map: HashMap<String, usize> = HashMap::new();
    all_data.iter().skip(1).take(n).enumerate().for_each(|pair| {
        let er_ee: Vec<&str> = (pair.1).split_whitespace().collect();
        ers.insert(er_ee[0].to_string());
        ees.insert(er_ee[1].to_string());
        if !ee_map.contains_key(er_ee[1]) {
            ee_map.insert(er_ee[1].to_string(), pair.0);
        }
    });
    solve(ers, ees, ee_map);
}
0