結果

問題 No.90 品物の並び替え
ユーザー kou6839kou6839
提出日時 2014-12-09 13:32:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 290 ms / 5,000 ms
コード長 1,060 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 74,360 KB
実行使用メモリ 56,496 KB
最終ジャッジ日時 2023-09-02 12:07:49
合計ジャッジ時間 4,620 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,588 KB
testcase_01 AC 166 ms
56,444 KB
testcase_02 AC 127 ms
55,620 KB
testcase_03 AC 153 ms
55,984 KB
testcase_04 AC 155 ms
56,236 KB
testcase_05 AC 170 ms
56,496 KB
testcase_06 AC 162 ms
56,268 KB
testcase_07 AC 134 ms
55,480 KB
testcase_08 AC 125 ms
55,828 KB
testcase_09 AC 290 ms
56,288 KB
権限があれば一括ダウンロードができます

ソースコード

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 int[] a;
	static void check(int now){
		if(now==r){
			eee();
			return;
		}
		for(int i=0;i<r;i++){
			if( (isUsed&1<<i)!=0) continue;
			isUsed+=1<<i;
			a[i]=now;
			check(now+1);
			isUsed-=1<<i;
		}
	}
	static void eee(){
		int temp=0;
		for(int i=0;i<g;i++){
			if(a[i1[i]]<a[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();
        a= new int[r];
        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(0);
        System.out.println(ans);
    }
}
0