結果

問題 No.628 Tagの勢い
ユーザー denderaKawazudenderaKawazu
提出日時 2018-02-14 00:11:19
言語 Java21
(openjdk 21)
結果
AC  
実行時間 277 ms / 2,000 ms
コード長 2,051 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 85,944 KB
実行使用メモリ 48,368 KB
最終ジャッジ日時 2024-04-16 20:06:38
合計ジャッジ時間 6,929 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
42,056 KB
testcase_01 AC 163 ms
42,752 KB
testcase_02 AC 155 ms
42,460 KB
testcase_03 AC 165 ms
42,636 KB
testcase_04 AC 159 ms
42,448 KB
testcase_05 AC 146 ms
42,292 KB
testcase_06 AC 163 ms
42,580 KB
testcase_07 AC 167 ms
42,668 KB
testcase_08 AC 169 ms
42,584 KB
testcase_09 AC 168 ms
42,568 KB
testcase_10 AC 210 ms
44,264 KB
testcase_11 AC 173 ms
42,936 KB
testcase_12 AC 273 ms
48,088 KB
testcase_13 AC 277 ms
48,368 KB
testcase_14 AC 275 ms
48,240 KB
testcase_15 AC 273 ms
48,332 KB
testcase_16 AC 248 ms
46,024 KB
testcase_17 AC 154 ms
42,460 KB
testcase_18 AC 147 ms
42,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.HashMap;
import java.util.Comparator;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            HashMap<String, Integer> tags = new HashMap<>();
            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                in.next();
                int m = in.nextInt();
                int s = in.nextInt();
                for (int j = 0; j < m; j++) {
                    String t = in.next();
                    tags.put(t, s + tags.getOrDefault(t, 0));
                }
            }

            ArrayList<Map.Entry<String, Integer>> entries = new ArrayList<Map.Entry<String, Integer>>(tags.entrySet());
            Collections.sort(entries, new Comparator<Map.Entry<String, Integer>>() {

                public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                    Integer val1 = o1.getValue();
                    Integer val2 = o2.getValue();
                    if (val1.equals(val2)) return o1.getKey().compareTo(o2.getKey());
                    else return val2.compareTo(val1);
                }
            });

            int count = Math.min(tags.size(), 10);
            for (int i = 0; i < count; i++) {
                out.println(entries.get(i).getKey() + " " + entries.get(i).getValue());
            }
        }

    }
}
0