結果

問題 No.943 取り調べ
ユーザー ks2mks2m
提出日時 2019-12-05 23:44:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,225 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 74,500 KB
実行使用メモリ 55,636 KB
最終ジャッジ日時 2023-08-24 19:27:43
合計ジャッジ時間 5,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
47,596 KB
testcase_01 AC 43 ms
49,272 KB
testcase_02 AC 42 ms
49,008 KB
testcase_03 AC 42 ms
49,248 KB
testcase_04 AC 186 ms
54,316 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 42 ms
49,264 KB
testcase_08 AC 198 ms
54,468 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 43 ms
49,276 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 190 ms
54,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;

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;
			for (int j = 0; j < n; j++) {
				if ((x & 1) == 1) {
					val += a[j];
					arr[j] = 0;
					for (int k = 0; k < arr.length; k++) {
						arr[k] &= (all - (1 << j));
					}
				}
				x /= 2;
			}
			boolean flg = true;
			for (int v : arr) {
				if (v != 0) {
					flg = false;
					break;
				}
			}
			if (flg) {
				ans = Math.min(ans, val);
			}
		}
		System.out.println(ans);
	}
}
0