結果
問題 | No.943 取り調べ |
ユーザー |
![]() |
提出日時 | 2019-12-05 23:56:15 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,559 bytes |
コンパイル時間 | 2,449 ms |
コンパイル使用メモリ | 78,336 KB |
実行使用メモリ | 47,588 KB |
最終ジャッジ日時 | 2024-12-23 04:37:17 |
合計ジャッジ時間 | 11,279 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 WA * 3 |
ソースコード
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); } }