結果
問題 | No.628 Tagの勢い |
ユーザー | htensai |
提出日時 | 2019-11-14 09:35:21 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 287 ms / 2,000 ms |
コード長 | 1,384 bytes |
コンパイル時間 | 2,406 ms |
コンパイル使用メモリ | 80,932 KB |
実行使用メモリ | 62,972 KB |
最終ジャッジ日時 | 2023-10-21 19:56:21 |
合計ジャッジ時間 | 7,305 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge9 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 167 ms
58,536 KB |
testcase_01 | AC | 167 ms
58,388 KB |
testcase_02 | AC | 165 ms
58,360 KB |
testcase_03 | AC | 166 ms
58,468 KB |
testcase_04 | AC | 162 ms
58,456 KB |
testcase_05 | AC | 163 ms
58,332 KB |
testcase_06 | AC | 170 ms
58,560 KB |
testcase_07 | AC | 172 ms
58,464 KB |
testcase_08 | AC | 176 ms
58,272 KB |
testcase_09 | AC | 173 ms
58,516 KB |
testcase_10 | AC | 198 ms
58,436 KB |
testcase_11 | AC | 178 ms
58,576 KB |
testcase_12 | AC | 285 ms
62,820 KB |
testcase_13 | AC | 286 ms
62,972 KB |
testcase_14 | AC | 287 ms
62,760 KB |
testcase_15 | AC | 283 ms
62,816 KB |
testcase_16 | AC | 268 ms
60,776 KB |
testcase_17 | AC | 168 ms
58,312 KB |
testcase_18 | AC | 165 ms
58,532 KB |
ソースコード
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 count = sc.nextInt(); int point = sc.nextInt(); for (int j = 0; j < count; j++) { String s = sc.next(); if (map.containsKey(s)) { map.put(s, map.get(s) + point); } else { map.put(s, point); } } } PriorityQueue<Tag> queue = new PriorityQueue<>(); for (Map.Entry<String, Integer> entry : map.entrySet()) { queue.add(new Tag(entry.getValue(), entry.getKey())); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < 10 && queue.size() > 0; i++) { sb.append(queue.poll()).append("\n"); } System.out.print(sb); } static class Tag implements Comparable<Tag>{ int score; String word; public Tag (int score, String word) { this.score = score; this.word = word; } public int compareTo(Tag another) { if (score == another.score) { return word.compareTo(another.word); } else { return another.score - score; } } public String toString() { return word + " " + score; } } }