結果
問題 | No.2364 Knapsack Problem |
ユーザー |
![]() |
提出日時 | 2023-07-01 15:33:24 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 56 ms / 3,000 ms |
コード長 | 823 bytes |
コンパイル時間 | 302 ms |
コンパイル使用メモリ | 82,172 KB |
実行使用メモリ | 66,940 KB |
最終ジャッジ日時 | 2024-07-08 01:47:10 |
合計ジャッジ時間 | 2,113 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
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))