結果

問題 No.90 品物の並び替え
ユーザー holegumaholeguma
提出日時 2015-08-17 21:56:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,112 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 74,848 KB
実行使用メモリ 53,932 KB
最終ジャッジ日時 2023-09-25 12:38:40
合計ジャッジ時間 3,389 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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.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