結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
holeguma
|
| 提出日時 | 2015-08-17 21:56:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,112 bytes |
| コンパイル時間 | 2,190 ms |
| コンパイル使用メモリ | 77,516 KB |
| 実行使用メモリ | 53,036 KB |
| 最終ジャッジ日時 | 2024-07-18 10:03:28 |
| 合計ジャッジ時間 | 3,874 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 9 |
ソースコード
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;
}
}
holeguma