結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー tentententen
提出日時 2021-01-25 09:30:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,507 bytes
コンパイル時間 2,382 ms
コンパイル使用メモリ 74,060 KB
実行使用メモリ 56,180 KB
最終ジャッジ日時 2023-09-03 19:46:45
合計ジャッジ時間 16,689 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,812 KB
testcase_01 AC 127 ms
55,712 KB
testcase_02 AC 128 ms
55,912 KB
testcase_03 AC 127 ms
55,848 KB
testcase_04 AC 127 ms
55,784 KB
testcase_05 AC 128 ms
55,616 KB
testcase_06 AC 127 ms
55,548 KB
testcase_07 AC 129 ms
55,620 KB
testcase_08 AC 129 ms
55,928 KB
testcase_09 AC 127 ms
55,836 KB
testcase_10 AC 128 ms
55,524 KB
testcase_11 AC 127 ms
55,860 KB
testcase_12 AC 130 ms
55,444 KB
testcase_13 AC 136 ms
55,600 KB
testcase_14 AC 137 ms
55,700 KB
testcase_15 AC 134 ms
55,824 KB
testcase_16 AC 134 ms
56,056 KB
testcase_17 AC 136 ms
55,788 KB
testcase_18 AC 131 ms
55,620 KB
testcase_19 AC 136 ms
55,524 KB
testcase_20 AC 136 ms
55,940 KB
testcase_21 AC 130 ms
55,852 KB
testcase_22 AC 138 ms
55,656 KB
testcase_23 AC 169 ms
55,604 KB
testcase_24 AC 188 ms
55,748 KB
testcase_25 AC 249 ms
55,396 KB
testcase_26 AC 160 ms
55,960 KB
testcase_27 AC 147 ms
56,008 KB
testcase_28 AC 251 ms
55,984 KB
testcase_29 AC 156 ms
55,896 KB
testcase_30 AC 170 ms
55,752 KB
testcase_31 AC 170 ms
56,076 KB
testcase_32 AC 159 ms
55,736 KB
testcase_33 AC 251 ms
55,952 KB
testcase_34 AC 254 ms
55,960 KB
testcase_35 AC 255 ms
55,960 KB
testcase_36 AC 248 ms
56,048 KB
testcase_37 AC 253 ms
55,952 KB
testcase_38 AC 255 ms
56,136 KB
testcase_39 AC 247 ms
55,888 KB
testcase_40 AC 252 ms
55,744 KB
testcase_41 AC 249 ms
55,892 KB
testcase_42 AC 255 ms
56,180 KB
testcase_43 AC 129 ms
55,704 KB
testcase_44 AC 250 ms
55,820 KB
testcase_45 AC 127 ms
56,176 KB
testcase_46 AC 245 ms
56,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] bases = new int[n];
        for (int i = 0; i < n; i++) {
            bases[i] = sc.nextInt();
        }
        int[][] matrix = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                matrix[i][j] = sc.nextInt();
            }
        }
        long ans = Long.MIN_VALUE;
        int idx = 0;
        for (int i = 1; i < (1 << n); i++) {
            long sum = 0;
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                sum += bases[j];
                for (int k = j + 1; k < n; k++) {
                    if ((i & (1 << k)) == 0) {
                        continue;
                    }
                    sum += matrix[j][k];
                }
            }
            if (ans < sum) {
                ans = sum;
                idx = i;
            }
        }
        System.out.println(ans);
        StringBuilder sb = new StringBuilder();
        boolean isFirst = true;
        for (int i = 0; i < n; i++) {
            if ((idx & (1 << i)) == 0) {
                continue;
            }
            if (!isFirst) {
                sb.append(" ");
            }
            isFirst = false;
            sb.append(i + 1);
        }
        System.out.println(sb);
    }
}
0