結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー tentententen
提出日時 2022-09-26 17:51:00
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,539 bytes
コンパイル時間 3,285 ms
コンパイル使用メモリ 74,900 KB
実行使用メモリ 54,676 KB
最終ジャッジ日時 2023-08-24 02:58:26
合計ジャッジ時間 14,006 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,396 KB
testcase_01 AC 44 ms
49,408 KB
testcase_02 AC 46 ms
49,780 KB
testcase_03 AC 45 ms
49,248 KB
testcase_04 AC 46 ms
49,460 KB
testcase_05 WA -
testcase_06 AC 45 ms
49,400 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 46 ms
49,376 KB
testcase_10 WA -
testcase_11 AC 46 ms
49,308 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 44 ms
49,336 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        long[] dp = new long[1 << n];
        long max = 0;
        int mask = 0;
        for (int i = 0; i < n; i++) {
            dp[1 << i] = sc.nextInt();
            if (max < dp[1 << i]) {
                max = dp[1 << i];
                mask = (1 << i);
            }
        }
        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();
            }
        }
        for (int i = 1; i < (1 << n); i++) {
            if (dp[i] > 0) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if ((i & (1 << j)) == 0) {
                    continue;
                }
                dp[i] += dp[1 << j] + dp[i ^ (1 << j)];
                for (int k = j + 1; k < n; k++) {
                    if ((i % (1 << k)) == 0) {
                        continue;
                    }
                    dp[i] += matrix[j][k];
                }
                break;
            }
            if (max < dp[i]) {
                max = dp[i];
                mask = i;
            }
        }
        System.out.println(max);
        ArrayList<Integer> ans = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            if ((mask & (1 << i)) > 0) {
                ans.add(i + 1);
            }
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < ans.size(); i++) {
            if (i > 0) {
                sb.append(" ");
            }
            sb.append(ans.get(i));
        }
        System.out.println(sb);
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0