結果

問題 No.628 Tagの勢い
ユーザー YamaKasaYamaKasa
提出日時 2018-03-31 03:28:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 292 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 3,600 ms
コンパイル使用メモリ 84,116 KB
実行使用メモリ 49,392 KB
最終ジャッジ日時 2024-04-16 20:11:25
合計ジャッジ時間 8,084 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
42,616 KB
testcase_01 AC 159 ms
42,836 KB
testcase_02 AC 142 ms
42,732 KB
testcase_03 AC 163 ms
42,548 KB
testcase_04 AC 143 ms
42,036 KB
testcase_05 AC 155 ms
42,604 KB
testcase_06 AC 163 ms
42,304 KB
testcase_07 AC 166 ms
42,556 KB
testcase_08 AC 172 ms
42,400 KB
testcase_09 AC 165 ms
42,952 KB
testcase_10 AC 184 ms
43,292 KB
testcase_11 AC 174 ms
42,828 KB
testcase_12 AC 284 ms
49,392 KB
testcase_13 AC 290 ms
48,748 KB
testcase_14 AC 279 ms
48,560 KB
testcase_15 AC 292 ms
48,844 KB
testcase_16 AC 257 ms
48,380 KB
testcase_17 AC 160 ms
42,692 KB
testcase_18 AC 163 ms
42,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;

public class Tag {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int []No = new int[N];
		int []S = new int[N];

		//String str[][] = new String[N][];
		HashMap<Integer, HashMap<Integer, String>> strD2
				= new HashMap<Integer, HashMap<Integer, String>>();
		for(int i = 0; i < N; i++) {
			No[i] =  scanner.nextInt();
			int M = scanner.nextInt();
			S[i] = scanner.nextInt();
			HashMap<Integer, String> strD1 = new HashMap<Integer, String>();
			for(int j = 0; j < M; j++) {
				String s = scanner.next();
				strD1.put(j, s);

			}
			strD2.put(i, strD1);
		}
		scanner.close();


		HashMap<String, Integer> pointHM = new HashMap<String,Integer>();
		pointHM.put(strD2.get(0).get(0), 0);
		int k;
		String key;
		for(int i = 0; i < N; i++) {
			k = strD2.get(i).size();
			for(int j = 0; j < k; j++) {
				key = strD2.get(i).get(j);
				if(pointHM.containsKey(key)) {
					int s = pointHM.get(key);
					pointHM.put(key, s + S[i]);
				}else {
					pointHM.put(key, S[i]);
				}
			}
		}
		Set<String> pointSet = pointHM.keySet();
		String s = pointSet.toString().substring(1, pointSet.toString().length() - 1);

		String[] arrayKey = s.split("[\\s]*,[\\s]*");

		int keyLen = arrayKey.length;
		int[]point = new int[keyLen];
		for(int i = 0; i < keyLen; i++) {
			point[i] = pointHM.get(arrayKey[i]);
		}


		int v;
		int j;
		String temp;
		for(int i = 1; i < keyLen; i++) {
			v = point[i];
			temp = arrayKey[i];
			j = i - 1;
			while( j >= 0 && arrayKey[j].compareTo(temp) > 0) {
				arrayKey[j + 1] = arrayKey[j];
				point[j + 1] = point[j];
				j--;
			}
			arrayKey[j + 1] = temp;
			point[j + 1] = v;
		}

		for(int i = 1; i < keyLen; i++) {
			v = point[i];
			temp = arrayKey[i];
			j = i - 1;
			while( j >= 0 && point[j] < v) {
				arrayKey[j + 1] = arrayKey[j];
				point[j + 1] = point[j];
				j--;
			}
			arrayKey[j + 1] = temp;
			point[j + 1] = v;
		}
		if(keyLen > 10) {
			for(int i = 0; i < 10; i++) {
				System.out.println(arrayKey[i] + " " + point[i]);
			}
		}else {
			for(int i = 0; i < keyLen; i++) {
				System.out.println(arrayKey[i] + " " + point[i]);
			}
		}

	}
}
0