結果

問題 No.2364 Knapsack Problem
ユーザー Akijin_007Akijin_007
提出日時 2023-06-30 23:00:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 96 ms / 3,000 ms
コード長 909 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 86,964 KB
実行使用メモリ 76,752 KB
最終ジャッジ日時 2023-09-21 17:17:09
合計ジャッジ時間 3,633 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,404 KB
testcase_01 AC 71 ms
71,300 KB
testcase_02 AC 73 ms
71,184 KB
testcase_03 AC 72 ms
71,396 KB
testcase_04 AC 78 ms
76,340 KB
testcase_05 AC 81 ms
76,312 KB
testcase_06 AC 80 ms
76,348 KB
testcase_07 AC 89 ms
76,632 KB
testcase_08 AC 72 ms
71,352 KB
testcase_09 AC 89 ms
76,420 KB
testcase_10 AC 90 ms
76,752 KB
testcase_11 AC 81 ms
76,316 KB
testcase_12 AC 93 ms
76,444 KB
testcase_13 AC 94 ms
76,436 KB
testcase_14 AC 92 ms
76,428 KB
testcase_15 AC 93 ms
76,736 KB
testcase_16 AC 93 ms
76,600 KB
testcase_17 AC 94 ms
76,412 KB
testcase_18 AC 94 ms
76,424 KB
testcase_19 AC 96 ms
76,408 KB
testcase_20 AC 96 ms
76,416 KB
testcase_21 AC 95 ms
76,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#int(input())
#map(int, input().split())
#list(map(int, input().split()))

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

import heapq

vs = [0] * (1 << (N+M))
ws = [0] * (1 << (N+M))

for i in range(1 << (N+M)):
    v = 0
    w = 0
    for j in range(N+M):
        if i & (1 << j):
            if j < N:
                w += A[j]
                v += B[j]
            else:
                w -= C[j-N]
                v -= D[j-N]
    vs[i] = v
    ws[i] = w

d = [0] * (1 << (N+M))
d[0] = 1

q = [0]
ans = 0
while q:
    t = q.pop()
    for i in range(N+M):
        if not t & (1 << i):
            x = t + (1 << i)
            if d[x] == 0 and ws[x] <= W and ws[x] >= 0:
                q.append(x)
                d[x] = 1
                ans = max(ans, vs[x])

print(ans)
0