結果

問題 No.90 品物の並び替え
ユーザー kuramukuramu
提出日時 2016-01-23 21:51:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 164 ms / 5,000 ms
コード長 1,474 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 77,644 KB
実行使用メモリ 55,856 KB
最終ジャッジ日時 2023-10-21 13:52:30
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,524 KB
testcase_01 AC 88 ms
54,536 KB
testcase_02 AC 53 ms
53,496 KB
testcase_03 AC 61 ms
53,560 KB
testcase_04 AC 61 ms
52,784 KB
testcase_05 AC 92 ms
55,036 KB
testcase_06 AC 87 ms
55,032 KB
testcase_07 AC 54 ms
52,432 KB
testcase_08 AC 53 ms
52,408 KB
testcase_09 AC 164 ms
55,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	static int[][] score;
	static int N;
	static int[] num;
	static boolean[] check;
	static int max;
	public static void main(String[] args) {
	      BufferedReader stdReader =new BufferedReader(new InputStreamReader(System.in));
	      try {
	    	String[] temps = stdReader.readLine().split(" ");
	    	N = Integer.parseInt(temps[0]);
	    	int m = Integer.parseInt(temps[1]);
	    	score = new int[N][N];
	    	for(int i=0;i<N;i++){
		    	Arrays.fill(score[i], 0);
	    	}
	    	num = new int[N];
	    	Arrays.fill(num, -1);
	    	check = new boolean[N];
	    	for(int i=0;i<m;i++){
	    		String[] temps2 = stdReader.readLine().split(" ");
	    		int item1 = Integer.parseInt(temps2[0]);
	    		int item2 = Integer.parseInt(temps2[1]);
	    		score[item1][item2] = Math.max(score[item1][item2], Integer.parseInt(temps2[2]));	
	    	}
	    	solve(0);
	    	System.out.println(max);
	      } catch (IOException e) {
			e.printStackTrace();
	      }
	}
		
	public static void getAns(){
		int ans = 0;
		for(int i=0;i<N;i++){
			for(int j=i+1;j<N;j++)
				ans += score[num[i]][num[j]];
		}
		max = Math.max(max, ans);
	}
	
	public static void solve(int n){
		if(n == N) {
			getAns();
		}else{
			for(int i=0;i<N;i++){
				if(!check[i]){
					check[i] = true;
					num[n] = i;
					solve(n+1);
					check[i] = false;
				}
			}
		}
	}
}
0