結果

問題 No.2364 Knapsack Problem
ユーザー ShirotsumeShirotsume
提出日時 2023-06-30 21:35:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,829 ms / 3,000 ms
コード長 921 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 95,424 KB
最終ジャッジ日時 2023-09-21 15:28:16
合計ジャッジ時間 66,369 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,820 ms
82,956 KB
testcase_01 AC 2,828 ms
83,076 KB
testcase_02 AC 2,826 ms
88,960 KB
testcase_03 AC 2,822 ms
83,304 KB
testcase_04 AC 2,822 ms
84,180 KB
testcase_05 AC 2,819 ms
90,780 KB
testcase_06 AC 2,824 ms
84,868 KB
testcase_07 AC 2,823 ms
83,896 KB
testcase_08 AC 2,829 ms
84,024 KB
testcase_09 AC 2,824 ms
91,948 KB
testcase_10 AC 2,823 ms
83,704 KB
testcase_11 AC 2,823 ms
87,204 KB
testcase_12 AC 2,828 ms
89,292 KB
testcase_13 AC 2,825 ms
92,784 KB
testcase_14 AC 2,824 ms
90,660 KB
testcase_15 AC 2,824 ms
89,432 KB
testcase_16 AC 2,825 ms
89,876 KB
testcase_17 AC 2,820 ms
88,836 KB
testcase_18 AC 2,821 ms
91,628 KB
testcase_19 AC 2,825 ms
92,496 KB
testcase_20 AC 2,820 ms
95,424 KB
testcase_21 AC 2,825 ms
88,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
import time
t1 = time.time()
n, m, w = mi()

a = li()
b = li()
c = [-v for v in li()]
d = [-v for v in li()]

WV = []

for x, y in zip(a, b):
    WV.append((x, y))

for x, y in zip(c, d):
    WV.append((x, y))

def solve(WV, w):
    n = len(WV)
    dp = [[-inf] * (w + 1) for _ in range(n + 1)]

    dp[0][0] = 0

    for i in range(n):
        x, y = WV[i]
        for j in range(w + 1):
            if 0 <= j + x <= w:
                dp[i + 1][j + x] = max(dp[i + 1][j + x], dp[i][j] + y)
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j])
    return max(dp[n])
ans = 0
while time.time() - t1 <= 2.7:
    random.shuffle(WV)
    ans = max(ans, solve(WV, w))

print(ans)
0