結果

問題 No.90 品物の並び替え
ユーザー tentententen
提出日時 2020-12-18 16:56:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 401 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 3,475 ms
コンパイル使用メモリ 78,272 KB
実行使用メモリ 64,044 KB
最終ジャッジ日時 2023-10-21 08:10:21
合計ジャッジ時間 5,524 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
57,440 KB
testcase_01 AC 256 ms
63,284 KB
testcase_02 AC 100 ms
55,720 KB
testcase_03 AC 162 ms
58,036 KB
testcase_04 AC 166 ms
56,392 KB
testcase_05 AC 270 ms
63,532 KB
testcase_06 AC 251 ms
63,544 KB
testcase_07 AC 142 ms
57,400 KB
testcase_08 AC 104 ms
56,036 KB
testcase_09 AC 401 ms
64,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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