結果

問題 No.2364 Knapsack Problem
ユーザー ShirotsumeShirotsume
提出日時 2023-06-30 21:33:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 921 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 87,176 KB
実行使用メモリ 91,368 KB
最終ジャッジ日時 2023-09-21 15:24:38
合計ジャッジ時間 43,161 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,811 ms
82,944 KB
testcase_01 AC 1,812 ms
82,608 KB
testcase_02 AC 1,811 ms
87,532 KB
testcase_03 AC 1,812 ms
83,168 KB
testcase_04 AC 1,815 ms
83,596 KB
testcase_05 AC 1,819 ms
87,524 KB
testcase_06 AC 1,812 ms
83,992 KB
testcase_07 AC 1,818 ms
83,156 KB
testcase_08 AC 1,814 ms
83,392 KB
testcase_09 AC 1,811 ms
88,068 KB
testcase_10 AC 1,816 ms
83,108 KB
testcase_11 AC 1,814 ms
85,404 KB
testcase_12 AC 1,814 ms
87,232 KB
testcase_13 AC 1,816 ms
89,020 KB
testcase_14 WA -
testcase_15 AC 1,816 ms
87,300 KB
testcase_16 AC 1,812 ms
87,380 KB
testcase_17 AC 1,821 ms
87,520 KB
testcase_18 WA -
testcase_19 AC 1,816 ms
89,796 KB
testcase_20 AC 1,812 ms
91,368 KB
testcase_21 AC 1,819 ms
87,340 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 <= 1.7:
    random.shuffle(WV)
    ans = max(ans, solve(WV, w))

print(ans)
0