結果

問題 No.90 品物の並び替え
ユーザー YamaKasaYamaKasa
提出日時 2018-07-05 03:20:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 865 ms / 5,000 ms
コード長 1,003 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 76,404 KB
実行使用メモリ 63,968 KB
最終ジャッジ日時 2023-09-13 17:40:30
合計ジャッジ時間 5,646 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,708 KB
testcase_01 AC 329 ms
63,968 KB
testcase_02 AC 127 ms
55,628 KB
testcase_03 AC 185 ms
57,820 KB
testcase_04 AC 205 ms
59,652 KB
testcase_05 AC 303 ms
62,328 KB
testcase_06 AC 290 ms
61,880 KB
testcase_07 AC 153 ms
56,040 KB
testcase_08 AC 127 ms
55,680 KB
testcase_09 AC 865 ms
61,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		String [][]item = new String[M][2];
		int []score = new int[M];
		for(int i = 0; i < M; i++) {
			for(int j = 0; j < 2; j++) {
				item[i][j] = scan.next();
			}
			score[i] = scan.nextInt();
		}
		scan.close();

		int l = 1;
		String s = "";
		for(int i = 0; i < N; i++) {
			l = l *(i + 1);
			s += Integer.toString(i);
		}
		s += " ";
		//String s = "012345678";
		int max = 0;
		for(int i = 1; i <= l; i++) {
			int p = 0;
			//System.out.println(s);
			for(int j = 0; j < M; j++) {
				int k1 = s.indexOf(item[j][0]);
				int k2 = s.indexOf(item[j][1]);
				if(k1 < k2) {
					p += score[j];
				}
			}
			if(max < p) {
				max = p;
			}
			int a = i;
			int b = 2;
			while(a % b == 0) {
				a /= b++;
			}
			s = new StringBuffer(s.substring(0, b)).reverse() + s.substring(b);
		}
		System.out.println(max);
	}
}
0