結果
| 問題 | No.1360 [Zelkova 4th Tune] 協和音 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-09-26 17:51:00 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,539 bytes |
| コンパイル時間 | 3,094 ms |
| コンパイル使用メモリ | 78,676 KB |
| 実行使用メモリ | 41,864 KB |
| 最終ジャッジ日時 | 2024-12-22 15:38:26 |
| 合計ジャッジ時間 | 10,361 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 38 |
ソースコード
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();
}
}
tenten