結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー ks2mks2m
提出日時 2021-01-22 22:03:28
言語 Java19
(openjdk 21)
結果
AC  
実行時間 563 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 2,758 ms
コンパイル使用メモリ 81,064 KB
実行使用メモリ 61,756 KB
最終ジャッジ日時 2023-08-27 19:15:08
合計ジャッジ時間 20,917 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,928 KB
testcase_01 AC 120 ms
54,184 KB
testcase_02 AC 120 ms
55,804 KB
testcase_03 AC 120 ms
55,748 KB
testcase_04 AC 119 ms
55,648 KB
testcase_05 AC 120 ms
56,172 KB
testcase_06 AC 120 ms
56,272 KB
testcase_07 AC 123 ms
56,048 KB
testcase_08 AC 122 ms
55,904 KB
testcase_09 AC 121 ms
56,632 KB
testcase_10 AC 123 ms
55,724 KB
testcase_11 AC 121 ms
55,692 KB
testcase_12 AC 123 ms
55,504 KB
testcase_13 AC 126 ms
55,820 KB
testcase_14 AC 134 ms
54,180 KB
testcase_15 AC 134 ms
56,140 KB
testcase_16 AC 130 ms
55,868 KB
testcase_17 AC 135 ms
55,868 KB
testcase_18 AC 149 ms
56,140 KB
testcase_19 AC 139 ms
56,292 KB
testcase_20 AC 135 ms
55,464 KB
testcase_21 AC 127 ms
55,892 KB
testcase_22 AC 139 ms
55,820 KB
testcase_23 AC 232 ms
59,360 KB
testcase_24 AC 275 ms
59,592 KB
testcase_25 AC 553 ms
61,756 KB
testcase_26 AC 186 ms
58,644 KB
testcase_27 AC 170 ms
56,144 KB
testcase_28 AC 556 ms
59,988 KB
testcase_29 AC 236 ms
59,880 KB
testcase_30 AC 247 ms
59,180 KB
testcase_31 AC 239 ms
58,984 KB
testcase_32 AC 200 ms
59,344 KB
testcase_33 AC 513 ms
59,996 KB
testcase_34 AC 556 ms
59,556 KB
testcase_35 AC 547 ms
59,908 KB
testcase_36 AC 563 ms
59,464 KB
testcase_37 AC 553 ms
59,924 KB
testcase_38 AC 529 ms
61,480 KB
testcase_39 AC 551 ms
60,308 KB
testcase_40 AC 549 ms
59,640 KB
testcase_41 AC 534 ms
59,960 KB
testcase_42 AC 506 ms
59,440 KB
testcase_43 AC 120 ms
55,644 KB
testcase_44 AC 548 ms
59,528 KB
testcase_45 AC 120 ms
56,068 KB
testcase_46 AC 519 ms
59,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int[][] b = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				b[i][j] = sc.nextInt();
			}
		}
		sc.close();

		long ans = 0;
		Set<Integer> as = new HashSet<>();
		int end = 1 << n;
		for (int i = 0; i < end; i++) {
			long val = 0;
			Set<Integer> set = new HashSet<>();
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					val += a[j];
					for (int j2 = 0; j2 < j; j2++) {
						if (set.contains(j2)) {
							val += b[j][j2];
						}
					}
					set.add(j);
				}
			}
			if (val >= ans) {
				ans = val;
				as = set;
			}
		}
		System.out.println(ans);
		StringBuilder sb = new StringBuilder();
		for (int i : as) {
			sb.append(i + 1).append(' ');
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}
0