結果

問題 No.628 Tagの勢い
ユーザー YamaKasaYamaKasa
提出日時 2018-03-31 03:18:36
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 2,694 bytes
コンパイル時間 3,718 ms
コンパイル使用メモリ 81,712 KB
実行使用メモリ 48,856 KB
最終ジャッジ日時 2024-04-16 20:11:17
合計ジャッジ時間 8,162 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 163 ms
42,708 KB
testcase_02 RE -
testcase_03 AC 154 ms
43,076 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 169 ms
42,696 KB
testcase_07 AC 163 ms
42,532 KB
testcase_08 AC 163 ms
44,104 KB
testcase_09 AC 165 ms
42,968 KB
testcase_10 AC 186 ms
42,528 KB
testcase_11 AC 173 ms
42,880 KB
testcase_12 AC 284 ms
48,748 KB
testcase_13 AC 277 ms
48,780 KB
testcase_14 AC 283 ms
48,856 KB
testcase_15 AC 286 ms
48,636 KB
testcase_16 AC 267 ms
48,708 KB
testcase_17 RE -
testcase_18 AC 158 ms
42,640 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();



//		for(int i = 0; i < N; i++) {
//			int k = strD2.get(i).size();
//			for(int j = 0; j < k; j++) {
//				String s = strD2.get(i).get(j);
//				System.out.print(s + " ");
//			}
//			System.out.println();
//		}
		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]*");
//		for(int i = 0; i < arrayKey.length; i++) {
//			System.out.println(arrayKey[i]);
//		}
		int keyLen = arrayKey.length;
		int[]point = new int[keyLen];
		for(int i = 0; i < keyLen; i++) {
			point[i] = pointHM.get(arrayKey[i]);
		}

//		for(int i = 0; i < keyLen; i++) {
//			System.out.println(arrayKey[i] + ": " + point[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;
		}
//		System.out.println("並び替え");
//		for(int i = 0; i < keyLen; i++) {
//			System.out.println(arrayKey[i] + ": " + point[i]);
//		}

		//System.out.println("降順");
		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;
		}
		for(int i = 0; i < 10; i++) {
			System.out.println(arrayKey[i] + " " + point[i]);
		}
	}
}
0