結果
問題 | No.1360 [Zelkova 4th Tune] 協和音 |
ユーザー | tenten |
提出日時 | 2022-09-26 17:51:00 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,539 bytes |
コンパイル時間 | 2,010 ms |
コンパイル使用メモリ | 79,008 KB |
実行使用メモリ | 56,452 KB |
最終ジャッジ日時 | 2024-06-02 00:13:56 |
合計ジャッジ時間 | 9,004 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
50,172 KB |
testcase_01 | AC | 48 ms
50,324 KB |
testcase_02 | AC | 49 ms
50,528 KB |
testcase_03 | AC | 46 ms
50,540 KB |
testcase_04 | AC | 46 ms
50,424 KB |
testcase_05 | WA | - |
testcase_06 | AC | 48 ms
50,396 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 48 ms
50,172 KB |
testcase_10 | WA | - |
testcase_11 | AC | 48 ms
50,396 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 | 49 ms
50,408 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
ソースコード
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(); } }