結果

問題 No.943 取り調べ
ユーザー ks2mks2m
提出日時 2019-12-05 22:52:47
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,288 bytes
コンパイル時間 4,592 ms
コンパイル使用メモリ 84,424 KB
実行使用メモリ 67,504 KB
最終ジャッジ日時 2023-08-24 18:34:05
合計ジャッジ時間 6,635 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
55,924 KB
testcase_01 AC 131 ms
55,820 KB
testcase_02 AC 135 ms
55,688 KB
testcase_03 AC 133 ms
55,516 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
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();
		Map<Integer, Set<Integer>> map0 = new HashMap<>();
		for (int i = 0; i < n; i++) {
			Set<Integer> set = new HashSet<>();
			map0.put(i, set);
			for (int j = 0; j < n; j++) {
				if (sc.nextInt() == 1) {
					set.add(j);
				}
			}
		}
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();

		int ans = Integer.MAX_VALUE;
		int end = 1 << n;
		for (int i = 0; i < end; i++) {
			Map<Integer, Set<Integer>> map = new HashMap<>();
			for (int j = 0; j < n; j++) {
				Set<Integer> set = new HashSet<>();
				set.addAll(map0.get(j));
				map.put(j, set);
			}

			int val = 0;
			for (int j = 0; j < n; j++) {
				if ((i >> j & 1) == 1) {
					val += a[j];
					map.remove(j);
					for (Integer k : map.keySet()) {
						map.get(k).remove(j);
					}
				}
			}
			boolean flg = true;
			for (Set<Integer> set : map.values()) {
				if (!set.isEmpty()) {
					flg = false;
					break;
				}
			}
			if (flg) {
				ans = Math.min(ans, val);
			}
		}
		System.out.println(ans);
	}
}
0