結果

問題 No.628 Tagの勢い
コンテスト
ユーザー tenten
提出日時 2020-10-09 12:54:17
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 1,580 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,801 ms
コンパイル使用メモリ 85,676 KB
実行使用メモリ 132,568 KB
最終ジャッジ日時 2026-04-02 21:36:44
合計ジャッジ時間 4,346 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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