結果
| 問題 |
No.2364 Knapsack Problem
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-11-24 02:27:12 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 3,000 ms |
| コード長 | 656 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 66,048 KB |
| 最終ジャッジ日時 | 2024-09-26 08:29:38 |
| 合計ジャッジ時間 | 2,292 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
n, m, W = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
D = list(map(int, input().split()))
A += [-c for c in C]
B += [-d for d in D]
n += m
W_ = [-1] * (1 << n)
V_ = [-1] * (1 << n)
ok = [False] * (1 << n)
ok[0] = True
W_[0] = 0
V_[0] = 0
for bit in range(1 << n):
for i in range(n):
if bit >> i & 1:
W_[bit] = W_[bit ^ (1 << i)] + A[i]
V_[bit] = V_[bit ^ (1 << i)] + B[i]
ok[bit] |= ok[bit ^ (1 << i)]
if W_[bit] < 0 or W < W_[bit]:
ok[bit] = False
ans = max([v for o, v in zip(ok, V_) if o])
print(ans)