結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー 小野寺健小野寺健
提出日時 2021-05-21 14:25:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 401 ms / 2,000 ms
コード長 1,174 bytes
コンパイル時間 3,855 ms
コンパイル使用メモリ 78,592 KB
実行使用メモリ 47,676 KB
最終ジャッジ日時 2024-04-18 14:17:01
合計ジャッジ時間 17,939 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
41,624 KB
testcase_01 AC 113 ms
41,472 KB
testcase_02 AC 129 ms
41,304 KB
testcase_03 AC 128 ms
41,676 KB
testcase_04 AC 114 ms
41,300 KB
testcase_05 AC 114 ms
41,304 KB
testcase_06 AC 127 ms
41,200 KB
testcase_07 AC 127 ms
41,372 KB
testcase_08 AC 128 ms
41,668 KB
testcase_09 AC 125 ms
41,508 KB
testcase_10 AC 125 ms
41,656 KB
testcase_11 AC 130 ms
41,116 KB
testcase_12 AC 135 ms
41,508 KB
testcase_13 AC 134 ms
41,376 KB
testcase_14 AC 145 ms
41,936 KB
testcase_15 AC 133 ms
41,912 KB
testcase_16 AC 146 ms
41,560 KB
testcase_17 AC 136 ms
41,416 KB
testcase_18 AC 134 ms
41,544 KB
testcase_19 AC 161 ms
41,584 KB
testcase_20 AC 138 ms
41,860 KB
testcase_21 AC 129 ms
41,220 KB
testcase_22 AC 150 ms
41,916 KB
testcase_23 AC 291 ms
47,444 KB
testcase_24 AC 270 ms
47,024 KB
testcase_25 AC 401 ms
47,420 KB
testcase_26 AC 184 ms
43,676 KB
testcase_27 AC 153 ms
42,048 KB
testcase_28 AC 388 ms
47,044 KB
testcase_29 AC 223 ms
46,592 KB
testcase_30 AC 265 ms
47,100 KB
testcase_31 AC 274 ms
47,224 KB
testcase_32 AC 201 ms
45,364 KB
testcase_33 AC 334 ms
47,392 KB
testcase_34 AC 388 ms
47,448 KB
testcase_35 AC 386 ms
47,552 KB
testcase_36 AC 395 ms
47,676 KB
testcase_37 AC 356 ms
47,396 KB
testcase_38 AC 365 ms
47,528 KB
testcase_39 AC 391 ms
47,228 KB
testcase_40 AC 357 ms
47,196 KB
testcase_41 AC 361 ms
47,224 KB
testcase_42 AC 365 ms
47,032 KB
testcase_43 AC 125 ms
40,012 KB
testcase_44 AC 367 ms
47,464 KB
testcase_45 AC 126 ms
41,232 KB
testcase_46 AC 345 ms
47,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class No1360 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> A = new ArrayList<Integer>();
		for (int i=0; i < N; i++) {
			A.add(scan.nextInt());
		}
		List<List<Integer>> B = new ArrayList<List<Integer>>();
		for (int i=0; i < N; i++) {
			List<Integer> l = new ArrayList<Integer>();
			for (int j=0; j < N; j++) {
				l.add(scan.nextInt());
			}
			B.add(l);
		}
		scan.close();
		long Max = Long.MIN_VALUE;
		int Max_comb = -1;
		for (int i=1; i < 1 << N; i++) {
			long point = 0;
			List<Integer> prev = new ArrayList<Integer>();
			for (int j=0; j < N; j++) {
				if ((i & (1 << j)) != 0) {
					point += A.get(j);
					for (int p : prev) {
						point += B.get(p).get(j);
					}
					prev.add(j);
				}
			}
			if (Max < point) {
				Max = point;
				Max_comb = i;
			}
		}
		List<String> J = new ArrayList<String>();
		for (int j=0; j < N; j++) {
			if ((Max_comb & (1 << j)) != 0) {
				J.add(String.valueOf(j+1));
			}
		}
		System.out.println(Max);
		System.out.println(String.join(" ", J));
	}

}
0