結果

問題 No.2364 Knapsack Problem
ユーザー rin204rin204
提出日時 2023-11-24 02:27:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 64 ms / 3,000 ms
コード長 656 bytes
コンパイル時間 385 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 66,672 KB
最終ジャッジ日時 2023-11-24 02:27:15
合計ジャッジ時間 2,815 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 56 ms
59,980 KB
testcase_05 AC 53 ms
62,256 KB
testcase_06 AC 44 ms
59,980 KB
testcase_07 AC 64 ms
66,672 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 54 ms
66,432 KB
testcase_10 AC 53 ms
66,668 KB
testcase_11 AC 48 ms
62,252 KB
testcase_12 AC 58 ms
66,652 KB
testcase_13 AC 57 ms
66,652 KB
testcase_14 AC 57 ms
66,652 KB
testcase_15 AC 56 ms
66,652 KB
testcase_16 AC 57 ms
66,652 KB
testcase_17 AC 58 ms
66,652 KB
testcase_18 AC 59 ms
66,652 KB
testcase_19 AC 57 ms
66,652 KB
testcase_20 AC 58 ms
66,652 KB
testcase_21 AC 58 ms
66,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0