結果

問題 No.2364 Knapsack Problem
ユーザー flygonflygon
提出日時 2023-06-30 21:46:03
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 868 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 145,684 KB
最終ジャッジ日時 2023-09-21 15:41:04
合計ジャッジ時間 16,679 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
77,188 KB
testcase_01 AC 117 ms
77,084 KB
testcase_02 AC 141 ms
78,484 KB
testcase_03 AC 124 ms
77,256 KB
testcase_04 AC 155 ms
79,344 KB
testcase_05 AC 167 ms
80,204 KB
testcase_06 AC 152 ms
78,584 KB
testcase_07 AC 666 ms
111,660 KB
testcase_08 AC 132 ms
77,340 KB
testcase_09 WA -
testcase_10 AC 415 ms
95,168 KB
testcase_11 AC 167 ms
80,528 KB
testcase_12 AC 1,276 ms
145,652 KB
testcase_13 AC 1,151 ms
145,508 KB
testcase_14 WA -
testcase_15 AC 1,412 ms
145,684 KB
testcase_16 AC 1,233 ms
145,528 KB
testcase_17 AC 1,314 ms
145,604 KB
testcase_18 AC 1,140 ms
145,524 KB
testcase_19 AC 1,338 ms
145,516 KB
testcase_20 AC 1,262 ms
145,456 KB
testcase_21 AC 1,146 ms
145,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

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()))
dp = [[0]*(510) for i in range(1<<(n+m))]
ans = 0
for bit in range(1<<(n+m)):
    for i in range(n+m):
        if not((bit>>i)&1): continue
        for w in range(510):
            if i < n and w >= a[i]:
                dp[bit][w] = max(dp[bit][w],dp[bit-(1<<i)][w-a[i]] + b[i])
            elif i >= n and w + c[i-n] <= W:
                dp[bit][w] = max(dp[bit][w],dp[bit-(1<<i)][w+c[i-n]] - d[i-n])
            ans = max((w <= W) * dp[bit][w], ans)
    

print(ans)
0