結果

問題 No.628 Tagの勢い
ユーザー trkage_tedtrkage_ted
提出日時 2018-01-13 21:41:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 1,409 bytes
コンパイル時間 3,060 ms
コンパイル使用メモリ 92,200 KB
実行使用メモリ 42,676 KB
最終ジャッジ日時 2024-04-16 20:05:22
合計ジャッジ時間 6,188 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
40,560 KB
testcase_01 AC 110 ms
40,616 KB
testcase_02 AC 110 ms
40,844 KB
testcase_03 AC 109 ms
40,612 KB
testcase_04 AC 116 ms
40,796 KB
testcase_05 AC 107 ms
40,588 KB
testcase_06 AC 109 ms
40,664 KB
testcase_07 AC 111 ms
40,304 KB
testcase_08 AC 118 ms
40,544 KB
testcase_09 AC 119 ms
40,548 KB
testcase_10 AC 112 ms
40,584 KB
testcase_11 AC 120 ms
40,876 KB
testcase_12 AC 202 ms
42,548 KB
testcase_13 AC 199 ms
42,676 KB
testcase_14 AC 203 ms
42,552 KB
testcase_15 AC 196 ms
42,636 KB
testcase_16 AC 163 ms
41,528 KB
testcase_17 AC 109 ms
40,472 KB
testcase_18 AC 112 ms
40,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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