結果

問題 No.90 品物の並び替え
ユーザー holegumaholeguma
提出日時 2015-08-17 21:56:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 1,130 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 74,416 KB
実行使用メモリ 52,732 KB
最終ジャッジ日時 2023-09-25 12:38:44
合計ジャッジ時間 3,351 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,524 KB
testcase_01 AC 84 ms
52,384 KB
testcase_02 AC 45 ms
49,436 KB
testcase_03 AC 50 ms
50,040 KB
testcase_04 AC 53 ms
50,364 KB
testcase_05 AC 86 ms
52,380 KB
testcase_06 AC 79 ms
52,332 KB
testcase_07 AC 47 ms
49,324 KB
testcase_08 AC 46 ms
49,444 KB
testcase_09 AC 127 ms
52,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.Arrays;

class Main{

static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MIN_VALUE/2;

public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line=br.readLine();
int n=Integer.parseInt(line.split(" ")[0]);
int m=Integer.parseInt(line.split(" ")[1]);
int[][] score=new int[n][n];
int[] a=new int[n];
while(m-->0){
line=br.readLine();
int x=Integer.parseInt(line.split(" ")[0]);
int y=Integer.parseInt(line.split(" ")[1]);
score[x][y]=Integer.parseInt(line.split(" ")[2]);
}
for(int i=0;i<n;i++) a[i]=i;
int ans=0;
do{
int cnt=0;
for(int i=0;i<n-1;i++){
for(int j=i+1;j<n;j++){
cnt+=score[a[i]][a[j]];
}
}
ans=Math.max(ans,cnt);
}while(next_permutation(a));
out.println(ans);
out.flush();
}

public static boolean next_permutation(int[] a){
for(int i=a.length-2;i>=0;i--){
if(a[i]<a[i+1]){
for(int j=a.length-1;;j--){
if(a[i]<a[j]){
int temp=a[i]; a[i]=a[j]; a[j]=temp;
for(i++,j=a.length-1;i<j;i++,j--){
temp=a[i]; a[i]=a[j]; a[j]=temp;
}
return true;
}
}
}
}
return false;
}
}
0