結果

問題 No.90 品物の並び替え
ユーザー tsunabittsunabit
提出日時 2020-02-04 22:36:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,114 ms / 5,000 ms
コード長 1,081 bytes
コンパイル時間 4,075 ms
コンパイル使用メモリ 79,284 KB
実行使用メモリ 67,376 KB
最終ジャッジ日時 2023-10-21 06:38:16
合計ジャッジ時間 8,678 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 189 ms
58,172 KB
testcase_01 AC 497 ms
67,188 KB
testcase_02 AC 177 ms
58,416 KB
testcase_03 AC 271 ms
64,364 KB
testcase_04 AC 281 ms
64,288 KB
testcase_05 AC 494 ms
67,328 KB
testcase_06 AC 452 ms
67,376 KB
testcase_07 AC 232 ms
58,456 KB
testcase_08 AC 176 ms
58,568 KB
testcase_09 AC 1,114 ms
66,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No90 {
	public static String[] ary;
	public static int MAX = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int y = 3 * m;
		
		ary = new String[y];
		for(int i = 0; i < y; i++) {
			ary[i] = sc.next();
		}
		
		// 商品の文字列作成
		String str = "";
		for(int i = 0; i < n; i++) {
			str = str + i;
		}
		
		permutation(str, "");
		
		System.out.println(MAX);
	}
	public static void permutation(String q, String ans){
		// Base Case
		if(q.length() <= 1) {
			String str = ans + q;
			
			int total = 0;
			for(int i = 0; i < ary.length; i=i+3) {
				String it1 = ary[i];
				String it2 = ary[i+1];
				int sc = Integer.parseInt(ary[i+2]);
				if(str.indexOf(it1) < str.indexOf(it2)) {
					total += sc;
				}
			}
			MAX = MAX < total? total : MAX;
 		}
		// General Case
		else {
			for (int i = 0; i < q.length(); i++) {
				permutation(q.substring(0, i) + q.substring(i + 1), ans + q.charAt(i));
			}
		}
	}
}
0