結果
問題 |
No.628 Tagの勢い
|
ユーザー |
![]() |
提出日時 | 2020-10-09 12:54:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 294 ms / 2,000 ms |
コード長 | 1,580 bytes |
コンパイル時間 | 2,557 ms |
コンパイル使用メモリ | 83,692 KB |
実行使用メモリ | 59,936 KB |
最終ジャッジ日時 | 2024-07-20 06:44:18 |
合計ジャッジ時間 | 7,639 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<String, Integer> map = new HashMap<>(); for (int i = 0; i < n; i++) { sc.nextInt(); int m = sc.nextInt(); int p = sc.nextInt(); for (int j = 0; j < m; j++) { String s = sc.next(); if (map.containsKey(s)) { map.put(s, map.get(s) + p); } else { map.put(s, p); } } } PriorityQueue<Tag> tags = new PriorityQueue<>(); for (Map.Entry<String, Integer> entry : map.entrySet()) { tags.add(new Tag(entry.getKey(), entry.getValue())); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10 && tags.size() > 0; i++) { sb.append(tags.poll()).append("\n"); } System.out.print(sb); } static class Tag implements Comparable<Tag> { String name; int value; public Tag(String name, int value) { this.name = name; this.value = value; } public int compareTo(Tag another) { if (value == another.value) { return name.compareTo(another.name); } else { return another.value - value; } } public String toString() { return name + " " + value; } } }