結果

問題 No.628 Tagの勢い
ユーザー uafr_csuafr_cs
提出日時 2018-01-05 21:31:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,467 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 86,276 KB
実行使用メモリ 48,452 KB
最終ジャッジ日時 2024-04-16 19:57:57
合計ジャッジ時間 6,755 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 162 ms
43,008 KB
testcase_01 AC 145 ms
42,796 KB
testcase_02 AC 163 ms
42,920 KB
testcase_03 AC 171 ms
42,684 KB
testcase_04 AC 156 ms
42,704 KB
testcase_05 AC 152 ms
42,816 KB
testcase_06 AC 160 ms
42,668 KB
testcase_07 AC 170 ms
42,568 KB
testcase_08 AC 174 ms
43,016 KB
testcase_09 AC 162 ms
42,908 KB
testcase_10 AC 194 ms
43,492 KB
testcase_11 AC 172 ms
43,276 KB
testcase_12 AC 274 ms
48,452 KB
testcase_13 AC 276 ms
47,968 KB
testcase_14 AC 272 ms
48,056 KB
testcase_15 AC 273 ms
48,112 KB
testcase_16 AC 266 ms
48,440 KB
testcase_17 AC 169 ms
42,884 KB
testcase_18 AC 163 ms
42,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static class Pair implements Comparable<Pair> {
		String tag;
		long score;
		
		public Pair(String tag, long score){
			this.tag = tag;
			this.score = score;
		}

		@Override
		public int compareTo(Pair o) {
			if(Long.compare(o.score, this.score) != 0){
				return Long.compare(o.score, this.score);
			}else{
				return this.tag.compareTo(o.tag);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		
		HashMap<String, Long> dict = new HashMap<String, Long>();
		
		for(int i = 0; i < N; i++){
			final int id = sc.nextInt();
			final int M = sc.nextInt();
			final int S = sc.nextInt();
			
			for(int j = 0; j < M; j++){
				final String tag = sc.next();
				if(!dict.containsKey(tag)){
					dict.put(tag, 0l);
				}
				dict.put(tag, dict.get(tag) + S);
			}
		}
		
		PriorityQueue<Pair> queue = new PriorityQueue<Pair>();
		for(final Entry<String, Long> entry : dict.entrySet()){
			queue.add(new Pair(entry.getKey(), entry.getValue()));
		}
		
		for(int i = 0; i < 10 && !queue.isEmpty(); i++){
			final Pair pair = queue.poll();
			
			System.out.println(pair.tag + " " + pair.score);
		}
		
		
	}
}
0