結果
問題 | No.628 Tagの勢い |
ユーザー |
|
提出日時 | 2020-06-04 16:50:38 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,194 bytes |
コンパイル時間 | 13,863 ms |
コンパイル使用メモリ | 388,892 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-29 13:27:40 |
合計ジャッジ時間 | 14,974 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
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() { use std::collections::HashMap; let n:usize = read(); let mut tag_map:HashMap<String,usize> = HashMap::new(); for _ in 0..n { let _no:usize = read(); let ms:Vec<usize> = read_vec(); let tags:Vec<String> = read_vec(); for tag in tags { let t = tag_map.entry(tag).or_insert(0); *t += ms[1]; } } let mut tags: Vec<_> = tag_map.into_iter().collect(); tags.sort_by(|a,b| { let cmp = a.1.cmp(&b.1); if cmp == std::cmp::Ordering::Equal { a.0.cmp(&b.0) } else { cmp.reverse() } }); use std::io::{stdout, Write, BufWriter}; let out = stdout(); let mut out = BufWriter::new(out.lock()); let max = if tags.len() > 10 { 10 } else { tags.len() }; for i in 0..max { writeln!(out, "{} {}", tags[i].0, tags[i].1).unwrap(); } }