結果

問題 No.938 賢人を探せ
ユーザー phsplsphspls
提出日時 2020-01-18 00:48:47
言語 Rust
(1.77.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,218 bytes
コンパイル時間 14,203 ms
コンパイル使用メモリ 402,104 KB
実行使用メモリ 8,736 KB
最終ジャッジ日時 2024-05-08 09:12:24
合計ジャッジ時間 15,800 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
8,736 KB
testcase_01 AC 1 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 1 ms
5,248 KB
testcase_04 AC 1 ms
5,248 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
testcase_08 AC 22 ms
6,960 KB
testcase_09 AC 17 ms
5,564 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 27 ms
6,920 KB
testcase_12 AC 19 ms
5,544 KB
testcase_13 AC 19 ms
5,544 KB
testcase_14 AC 18 ms
5,380 KB
testcase_15 AC 19 ms
5,412 KB
testcase_16 AC 18 ms
5,476 KB
testcase_17 AC 18 ms
5,540 KB
testcase_18 AC 19 ms
5,424 KB
testcase_19 AC 18 ms
5,412 KB
testcase_20 AC 19 ms
5,420 KB
testcase_21 AC 19 ms
5,544 KB
testcase_22 AC 60 ms
8,584 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