結果

問題 No.628 Tagの勢い
ユーザー tentententen
提出日時 2020-10-09 12:54:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 261 ms / 2,000 ms
コード長 1,580 bytes
コンパイル時間 2,290 ms
コンパイル使用メモリ 77,976 KB
実行使用メモリ 61,700 KB
最終ジャッジ日時 2023-09-27 12:36:24
合計ジャッジ時間 7,299 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 150 ms
56,844 KB
testcase_01 AC 151 ms
57,024 KB
testcase_02 AC 149 ms
56,512 KB
testcase_03 AC 146 ms
56,976 KB
testcase_04 AC 143 ms
56,676 KB
testcase_05 AC 150 ms
56,932 KB
testcase_06 AC 149 ms
56,680 KB
testcase_07 AC 155 ms
56,880 KB
testcase_08 AC 160 ms
57,100 KB
testcase_09 AC 155 ms
56,724 KB
testcase_10 AC 172 ms
57,244 KB
testcase_11 AC 160 ms
57,052 KB
testcase_12 AC 254 ms
61,536 KB
testcase_13 AC 261 ms
61,700 KB
testcase_14 AC 255 ms
61,680 KB
testcase_15 AC 255 ms
61,080 KB
testcase_16 AC 241 ms
60,908 KB
testcase_17 AC 151 ms
56,988 KB
testcase_18 AC 152 ms
56,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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