結果
問題 | No.943 取り調べ |
ユーザー | htensai |
提出日時 | 2020-02-17 09:06:22 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 111 ms / 1,206 ms |
コード長 | 1,331 bytes |
コンパイル時間 | 2,322 ms |
コンパイル使用メモリ | 77,988 KB |
実行使用メモリ | 39,532 KB |
最終ジャッジ日時 | 2024-04-16 03:44:49 |
合計ジャッジ時間 | 4,957 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
36,936 KB |
testcase_01 | AC | 52 ms
36,848 KB |
testcase_02 | AC | 53 ms
37,060 KB |
testcase_03 | AC | 52 ms
36,484 KB |
testcase_04 | AC | 110 ms
39,532 KB |
testcase_05 | AC | 109 ms
39,484 KB |
testcase_06 | AC | 109 ms
39,068 KB |
testcase_07 | AC | 53 ms
36,600 KB |
testcase_08 | AC | 109 ms
39,060 KB |
testcase_09 | AC | 80 ms
38,412 KB |
testcase_10 | AC | 81 ms
38,332 KB |
testcase_11 | AC | 84 ms
38,248 KB |
testcase_12 | AC | 55 ms
36,924 KB |
testcase_13 | AC | 55 ms
36,480 KB |
testcase_14 | AC | 57 ms
37,148 KB |
testcase_15 | AC | 56 ms
37,084 KB |
testcase_16 | AC | 54 ms
37,000 KB |
testcase_17 | AC | 84 ms
38,792 KB |
testcase_18 | AC | 56 ms
36,668 KB |
testcase_19 | AC | 55 ms
36,948 KB |
testcase_20 | AC | 55 ms
37,060 KB |
testcase_21 | AC | 54 ms
36,836 KB |
testcase_22 | AC | 80 ms
38,548 KB |
testcase_23 | AC | 111 ms
39,296 KB |
ソースコード
import java.util.*; import java.io.*; public class Main { static int[] cost; static int[] trust; static int[] dp; static int n; public static void main (String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); n = Integer.parseInt(br.readLine()); trust = new int[n]; for (int i = 0; i < n; i++) { String[] line = br.readLine().split(" ", n); for (int j = 0; j < n; j++) { trust[i] += Integer.parseInt(line[j]) << j; } } cost = new int[n]; String[] line = br.readLine().split(" ", n); for (int i = 0; i < n; i++) { cost[i] = Integer.parseInt(line[i]); } dp = new int[1 << n]; Arrays.fill(dp, -1); System.out.println(dfw((1 << n) - 1)); } static int dfw(int key) { if (key == 0) { return 0; } if (dp[key] != -1) { return dp[key]; } int min = Integer.MAX_VALUE / 10; for (int i = 0; i < n; i++) { if (((1 << i) & key) == 0) { continue; } int add = 0; if ((key & trust[i]) != trust[i]) { add += cost[i]; } min = Math.min(min, dfw(key ^ (1 << i)) + add); } dp[key] = min; return min; } }