結果

問題 No.628 Tagの勢い
ユーザー iwotiwot
提出日時 2020-06-04 16:50:38
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,194 bytes
コンパイル時間 3,328 ms
コンパイル使用メモリ 164,972 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 18:39:09
合計ジャッジ時間 4,643 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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();
  }
}
0