結果
問題 |
No.628 Tagの勢い
|
ユーザー |
![]() |
提出日時 | 2018-01-13 21:41:24 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 182 ms / 2,000 ms |
コード長 | 1,409 bytes |
コンパイル時間 | 2,707 ms |
コンパイル使用メモリ | 90,068 KB |
実行使用メモリ | 54,712 KB |
最終ジャッジ日時 | 2024-10-07 22:26:15 |
合計ジャッジ時間 | 6,017 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Collectors; import static java.util.Comparator.*; public class Main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader inReader = new BufferedReader(new InputStreamReader(System.in)); int element = Integer.valueOf(inReader.readLine()); Map<String, Integer> tagScore = new HashMap<>(); for (int i = 0; i < element; i++) { int imageNo = Integer.valueOf(inReader.readLine()); String[] inputs = inReader.readLine().split(" "); int tagCount = Integer.valueOf(inputs[0]); int score = Integer.valueOf(inputs[1]); String tags[] = inReader.readLine().split(" "); for (String tag : tags) { Integer now = tagScore.get(tag); if (now == null) now = 0; tagScore.put(tag, now + score); } } List<Entry<String, Integer>> sorted = tagScore .entrySet() .stream() .sorted(comparing(Entry<String, Integer>::getValue).reversed() .thenComparing(Entry<String, Integer>::getKey)) .collect(Collectors.toList()); int count = 0; for (Entry<String, Integer> entry : sorted) { System.out.println(entry.getKey() + " " + entry.getValue()); count++; if (10 <= count) break; } } }