結果
問題 | No.943 取り調べ |
ユーザー | tenten |
提出日時 | 2023-03-16 09:53:07 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 113 ms / 1,206 ms |
コード長 | 2,311 bytes |
コンパイル時間 | 2,637 ms |
コンパイル使用メモリ | 88,716 KB |
実行使用メモリ | 55,076 KB |
最終ジャッジ日時 | 2023-10-18 12:55:29 |
合計ジャッジ時間 | 5,584 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
53,496 KB |
testcase_01 | AC | 56 ms
53,524 KB |
testcase_02 | AC | 55 ms
53,536 KB |
testcase_03 | AC | 54 ms
53,524 KB |
testcase_04 | AC | 106 ms
55,028 KB |
testcase_05 | AC | 106 ms
54,888 KB |
testcase_06 | AC | 111 ms
54,856 KB |
testcase_07 | AC | 54 ms
53,540 KB |
testcase_08 | AC | 106 ms
54,748 KB |
testcase_09 | AC | 83 ms
54,784 KB |
testcase_10 | AC | 86 ms
55,076 KB |
testcase_11 | AC | 88 ms
54,868 KB |
testcase_12 | AC | 56 ms
52,432 KB |
testcase_13 | AC | 55 ms
53,476 KB |
testcase_14 | AC | 56 ms
53,532 KB |
testcase_15 | AC | 56 ms
53,528 KB |
testcase_16 | AC | 56 ms
53,532 KB |
testcase_17 | AC | 89 ms
54,992 KB |
testcase_18 | AC | 54 ms
53,532 KB |
testcase_19 | AC | 55 ms
53,540 KB |
testcase_20 | AC | 55 ms
53,540 KB |
testcase_21 | AC | 53 ms
53,536 KB |
testcase_22 | AC | 84 ms
54,792 KB |
testcase_23 | AC | 113 ms
55,028 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] factors = new int[n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { factors[i] += (sc.nextInt() << j); } } int[] costs = new int[n]; for (int i = 0; i < n; i++) { costs[i] = sc.nextInt(); } int[] dp = new int[1 << n]; for (int i = 1; i < (1 << n); i++) { dp[i] = Integer.MAX_VALUE; for (int j = 0; j < n; j++) { if ((i & (1 << j)) == 0) { continue; } if ((i & factors[j]) == factors[j]) { dp[i] = Math.min(dp[i], dp[i ^ (1 << j)]); } else { dp[i] = Math.min(dp[i], dp[i ^ (1 << j)] + costs[j]); } } } System.out.println(dp[(1 << n) - 1]); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }