結果

問題 No.90 品物の並び替え
ユーザー kou6839kou6839
提出日時 2014-12-09 13:12:28
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,098 bytes
コンパイル時間 3,417 ms
コンパイル使用メモリ 77,216 KB
実行使用メモリ 51,388 KB
最終ジャッジ日時 2023-09-02 12:06:16
合計ジャッジ時間 10,242 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
46,456 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.*;
import java.util.*;
 
public class Main {
	static int[] i1;
	static int[] i2;
	static int[] ten;
	static int ans=0;
	static int r;
	static int g;
	static int isUsed=0;
	static void check(String now){
		if(now.length()==r){
			eee(now);
			return;
		}
		for(int i=0;i<r;i++){
			if( (isUsed&1<<i)==1) continue;
			String ttt=new String(now);
			ttt+=i;
			isUsed+=1<<i;
			check(ttt);
			isUsed-=1<<i;
		}
	}
	static void eee(String now){
		int temp=0;
		for(int i=0;i<g;i++){
			if(now.indexOf(i1[i]+"")<now.indexOf(i2[i]+"") ) temp+=ten[i];
		}
		ans=Math.max(ans, temp);
	}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        r = sc.nextInt();
        g = sc.nextInt();
        ArrayList<Integer> uuu= new ArrayList<>();
        i1 = new int[g];
        i2=new int[g];
        ten = new int[g];
        for(int i=0;i<g;i++){
        	i1[i]=sc.nextInt();
        	i2[i]=sc.nextInt();
        	ten[i]=sc.nextInt();
        }
        check("");
        System.out.println(ans);
    }
}
0