結果

問題 No.2364 Knapsack Problem
ユーザー titiatitia
提出日時 2023-06-30 21:38:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 3,000 ms
コード長 667 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 86,720 KB
実行使用メモリ 76,736 KB
最終ジャッジ日時 2023-09-21 15:31:10
合計ジャッジ時間 3,106 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,240 KB
testcase_01 AC 67 ms
71,080 KB
testcase_02 AC 67 ms
71,248 KB
testcase_03 AC 69 ms
71,196 KB
testcase_04 AC 68 ms
71,196 KB
testcase_05 AC 69 ms
71,036 KB
testcase_06 AC 69 ms
71,196 KB
testcase_07 AC 86 ms
76,236 KB
testcase_08 AC 68 ms
70,888 KB
testcase_09 AC 85 ms
76,304 KB
testcase_10 AC 86 ms
76,436 KB
testcase_11 AC 69 ms
71,192 KB
testcase_12 AC 87 ms
76,524 KB
testcase_13 AC 88 ms
76,652 KB
testcase_14 AC 87 ms
76,632 KB
testcase_15 AC 88 ms
76,736 KB
testcase_16 AC 88 ms
76,380 KB
testcase_17 AC 88 ms
76,312 KB
testcase_18 AC 87 ms
76,304 KB
testcase_19 AC 90 ms
76,416 KB
testcase_20 AC 87 ms
76,268 KB
testcase_21 AC 86 ms
76,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

for i in range(M):
    C[i]=-C[i]
    D[i]=-D[i]

A+=C
B+=D

DP=[0]*(1<<(N+M))
DP[0]=1
ANS=0
for i in range(1<<(N+M)):
    if DP[i]==1:
        w=0
        v=0
        for j in range(N+M):
            if i & (1<<j) != 0:
                w+=A[j]
                v+=B[j]

        for j in range(N+M):
            if i & (1<<j) == 0:

                if 0<=w+A[j]<=W:
                    DP[i^(1<<j)]=1
                    ANS=max(ANS,v+B[j])
            
print(ANS)
0