結果

問題 No.943 取り調べ
ユーザー ks2mks2m
提出日時 2019-12-05 23:56:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,559 bytes
コンパイル時間 3,307 ms
コンパイル使用メモリ 74,652 KB
実行使用メモリ 59,568 KB
最終ジャッジ日時 2023-08-24 19:28:22
合計ジャッジ時間 12,631 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,224 KB
testcase_01 AC 44 ms
49,312 KB
testcase_02 AC 45 ms
49,268 KB
testcase_03 WA -
testcase_04 AC 792 ms
59,156 KB
testcase_05 AC 1,094 ms
59,188 KB
testcase_06 AC 1,079 ms
59,392 KB
testcase_07 WA -
testcase_08 AC 818 ms
59,320 KB
testcase_09 AC 519 ms
59,300 KB
testcase_10 AC 458 ms
58,628 KB
testcase_11 AC 445 ms
59,200 KB
testcase_12 WA -
testcase_13 AC 79 ms
51,572 KB
testcase_14 AC 94 ms
52,536 KB
testcase_15 AC 49 ms
50,972 KB
testcase_16 AC 44 ms
49,204 KB
testcase_17 AC 627 ms
59,180 KB
testcase_18 AC 46 ms
49,196 KB
testcase_19 AC 66 ms
52,084 KB
testcase_20 AC 49 ms
49,840 KB
testcase_21 AC 45 ms
49,236 KB
testcase_22 AC 603 ms
58,780 KB
testcase_23 AC 1,161 ms
59,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Queue;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] arr0 = new int[n];
		for (int i = 0; i < n; i++) {
			String[] sa = br.readLine().split(" ");
			for (int j = 0; j < n; j++) {
				if (Integer.parseInt(sa[j]) == 1) {
					arr0[i] += 1 << j;
				}
			}
		}
		String[] sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		int ans = Integer.MAX_VALUE;
		int end = 1 << n;
		int all = end - 1;
		for (int i = 0; i < end; i++) {
			int[] arr = new int[n];
			System.arraycopy(arr0, 0, arr, 0, n);

			int val = 0;
			int x = i;
			Set<Integer> set = new HashSet<>();
			for (int j = 0; j < n; j++) {
				set.add(j);
			}
			Queue<Integer> que = new ArrayDeque<>();
			for (int j = 0; j < n; j++) {
				if ((x & 1) == 1) {
					val += a[j];
					arr[j] = 0;
					set.remove(j);
					que.add(j);
				}
				x /= 2;
			}
			while (!que.isEmpty()) {
				int j = que.poll();
				Integer[] rem = set.toArray(new Integer[0]);
				for (int k : rem) {
					arr[k] &= (all - (1 << j));
					if (arr[k] == 0) {
						set.remove(k);
						que.add(k);
					}
				}
			}
			if (set.isEmpty()) {
				ans = Math.min(ans, val);
			}
		}
		System.out.println(ans);
	}
}
0