結果

問題 No.90 品物の並び替え
ユーザー htensaihtensai
提出日時 2020-01-22 13:01:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 502 ms / 5,000 ms
コード長 999 bytes
コンパイル時間 2,684 ms
コンパイル使用メモリ 74,136 KB
実行使用メモリ 62,764 KB
最終ジャッジ日時 2023-09-22 06:22:38
合計ジャッジ時間 5,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,392 KB
testcase_01 AC 281 ms
62,164 KB
testcase_02 AC 128 ms
55,464 KB
testcase_03 AC 180 ms
57,128 KB
testcase_04 AC 183 ms
57,740 KB
testcase_05 AC 284 ms
62,364 KB
testcase_06 AC 274 ms
61,892 KB
testcase_07 AC 152 ms
55,540 KB
testcase_08 AC 128 ms
55,660 KB
testcase_09 AC 502 ms
62,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static int n;
    static int[][] matrix;
    static int max = 0;
    public static void main(String[]  args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int m = sc.nextInt();
        matrix = new int[n][n];
        for (int i = 0; i < m; i++) {
            matrix[sc.nextInt()][sc.nextInt()] = sc.nextInt();
        }
        search(0, 0, new HashSet<Integer>());
        System.out.println(max);
    }
    
    static void search(int idx, int score, HashSet<Integer> used) {
        if (idx >= n) {
            max = Math.max(max, score);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (used.contains(i)) {
                continue;
            }
            int added = 0;
            for (int x : used) {
                added += matrix[x][i];
            }
            used.add(i);
            search(idx + 1, score + added, used);
            used.remove(i);
        }
    }
}
0