結果
| 問題 | No.628 Tagの勢い | 
| コンテスト | |
| ユーザー |  htensai | 
| 提出日時 | 2019-11-14 09:35:21 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 291 ms / 2,000 ms | 
| コード長 | 1,384 bytes | 
| コンパイル時間 | 2,550 ms | 
| コンパイル使用メモリ | 83,928 KB | 
| 実行使用メモリ | 48,160 KB | 
| 最終ジャッジ日時 | 2024-09-21 21:21:39 | 
| 合計ジャッジ時間 | 7,384 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 19 | 
ソースコード
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 count = sc.nextInt();
		    int point = sc.nextInt();
		    for (int j = 0; j < count; j++) {
		        String s = sc.next();
		        if (map.containsKey(s)) {
		            map.put(s, map.get(s) + point);
		        } else {
		            map.put(s, point);
		        }
		    }
		}
		PriorityQueue<Tag> queue = new PriorityQueue<>();
		for (Map.Entry<String, Integer> entry : map.entrySet()) {
		    queue.add(new Tag(entry.getValue(), entry.getKey()));
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < 10 && queue.size() > 0; i++) {
		    sb.append(queue.poll()).append("\n");
		}
		System.out.print(sb);
	}
	
	static class Tag implements Comparable<Tag>{
	    int score;
	    String word;
	    
	    public Tag (int score, String word) {
	        this.score = score;
	        this.word = word;
	    }
	    
	    public int compareTo(Tag another) {
	        if (score == another.score) {
	            return word.compareTo(another.word);
	        } else {
	            return another.score - score;
	        }
	    }
	    
	    public String toString() {
	        return word + " " + score;
	    }
	}
}
            
            
            
        