結果
| 問題 |
No.90 品物の並び替え
|
| コンテスト | |
| ユーザー |
jp_ste
|
| 提出日時 | 2016-05-26 04:21:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 941 ms / 5,000 ms |
| コード長 | 1,503 bytes |
| コンパイル時間 | 2,483 ms |
| コンパイル使用メモリ | 80,428 KB |
| 実行使用メモリ | 59,736 KB |
| 最終ジャッジ日時 | 2024-10-07 14:42:16 |
| 合計ジャッジ時間 | 6,310 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
ソースコード
import java.util.Scanner;
public class Main {
static int N, M;
static int list[][];
static boolean flag[];
static int ans = 0;
public static void main(String[] args) {
try (Scanner scan = new Scanner(System.in)) {
N = Integer.parseInt(scan.next());
M = Integer.parseInt(scan.next());
flag = new boolean[N];
list = new int[N][N];
for(int i=0; i<M; i++) {
int y = Integer.parseInt(scan.next());
int x = Integer.parseInt(scan.next());
int v = Integer.parseInt(scan.next());
list[y][x] = v;
}
pattern("");
System.out.println(ans);
}
}
static void pattern(String now) {
if(now.length() == N) {
int sum = 0;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
if(list[i][j] > 0) {
int left = now.indexOf(""+i);
int right = now.indexOf(""+j);
if(left < right) {
sum += list[i][j];
}
}
}
}
ans = Math.max(ans, sum);
return;
}
for(int i=0; i<N; i++) {
if(!flag[i]) {
flag[i] = true;
pattern(now + i);
flag[i] = false;
}
}
}
}
jp_ste