結果

問題 No.2364 Knapsack Problem
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-07-24 02:45:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 61 ms / 3,000 ms
コード長 778 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,932 KB
実行使用メモリ 70,580 KB
最終ジャッジ日時 2023-10-25 10:28:50
合計ジャッジ時間 2,249 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,564 KB
testcase_01 AC 43 ms
55,564 KB
testcase_02 AC 41 ms
55,564 KB
testcase_03 AC 39 ms
55,564 KB
testcase_04 AC 39 ms
55,564 KB
testcase_05 AC 38 ms
55,564 KB
testcase_06 AC 41 ms
55,564 KB
testcase_07 AC 58 ms
70,460 KB
testcase_08 AC 40 ms
55,564 KB
testcase_09 AC 54 ms
66,412 KB
testcase_10 AC 59 ms
68,480 KB
testcase_11 AC 42 ms
55,564 KB
testcase_12 AC 58 ms
70,564 KB
testcase_13 AC 55 ms
68,516 KB
testcase_14 AC 57 ms
68,408 KB
testcase_15 AC 59 ms
68,404 KB
testcase_16 AC 59 ms
70,564 KB
testcase_17 AC 57 ms
68,392 KB
testcase_18 AC 57 ms
68,484 KB
testcase_19 AC 56 ms
68,492 KB
testcase_20 AC 59 ms
70,476 KB
testcase_21 AC 61 ms
70,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
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()))
N += M
A += [-i for i in C]
B += [-i for i in D]
INF = (1<<60)
dp = [-INF]*(1<<N)
dp[0] = 0
def is_ok(val):
    return 0<=val<=W
ans = 0
val = [0]*(1<<N)
for i in range(1<<N):
    if dp[i]==-INF:
        continue
    for j in range(N):
        if (i>>j)&1:
            continue
        else:
            if is_ok(dp[i]+A[j]):
                dp[i|(1<<j)] = dp[i]+A[j]
                val[i|(1<<j)] = val[i]+B[j]
                ans = max(ans,val[i|(1<<j)])
print(ans)
0