結果
問題 | No.2364 Knapsack Problem |
ユーザー | ntuda |
提出日時 | 2023-07-01 15:33:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 95 ms / 3,000 ms |
コード長 | 823 bytes |
コンパイル時間 | 376 ms |
コンパイル使用メモリ | 87,028 KB |
実行使用メモリ | 76,952 KB |
最終ジャッジ日時 | 2023-09-22 09:41:02 |
合計ジャッジ時間 | 3,431 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
71,192 KB |
testcase_01 | AC | 70 ms
71,300 KB |
testcase_02 | AC | 72 ms
71,144 KB |
testcase_03 | AC | 68 ms
71,092 KB |
testcase_04 | AC | 70 ms
71,280 KB |
testcase_05 | AC | 69 ms
71,228 KB |
testcase_06 | AC | 69 ms
71,316 KB |
testcase_07 | AC | 95 ms
76,856 KB |
testcase_08 | AC | 69 ms
71,320 KB |
testcase_09 | AC | 82 ms
76,952 KB |
testcase_10 | AC | 84 ms
76,616 KB |
testcase_11 | AC | 69 ms
71,328 KB |
testcase_12 | AC | 83 ms
76,808 KB |
testcase_13 | AC | 84 ms
76,868 KB |
testcase_14 | AC | 86 ms
76,808 KB |
testcase_15 | AC | 85 ms
76,800 KB |
testcase_16 | AC | 84 ms
76,388 KB |
testcase_17 | AC | 84 ms
76,796 KB |
testcase_18 | AC | 85 ms
76,928 KB |
testcase_19 | AC | 85 ms
76,624 KB |
testcase_20 | AC | 86 ms
76,804 KB |
testcase_21 | AC | 85 ms
76,612 KB |
ソースコード
N, M, W0 = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = [-i for i in list(map(int, input().split()))] D = [-i for i in list(map(int, input().split()))] NM = N + M W = [0] * (1 << NM) V = [0] * (1 << NM) checked = set() ans = 0 q = [] for i in range(N): x = 1 << i q.append(1 << i) W[x] = A[i] V[x] = B[i] A += C B += D while q: x = q.pop(-1) v = V[x] w = W[x] for i in range(NM): if x >> i & 1: continue y = x | (1 << i) if y in checked: continue if W0 < w + A[i]: checked.add(y) if 0 <= w + A[i] <= W0: y = x | (1 << i) W[y] = w + A[i] V[y] = v + B[i] q.append(y) checked.add(y) print(max(V))