結果

問題 No.2429 Happiest Tabehodai Ways
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2023-08-19 03:53:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 87,436 KB
実行使用メモリ 77,692 KB
最終ジャッジ日時 2023-09-03 03:05:32
合計ジャッジ時間 5,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
76,756 KB
testcase_01 AC 64 ms
71,312 KB
testcase_02 AC 69 ms
71,088 KB
testcase_03 AC 65 ms
71,408 KB
testcase_04 AC 66 ms
71,596 KB
testcase_05 AC 62 ms
71,400 KB
testcase_06 AC 65 ms
71,268 KB
testcase_07 AC 61 ms
71,428 KB
testcase_08 AC 61 ms
71,268 KB
testcase_09 AC 69 ms
75,952 KB
testcase_10 AC 69 ms
75,940 KB
testcase_11 AC 74 ms
76,308 KB
testcase_12 AC 75 ms
76,588 KB
testcase_13 AC 79 ms
76,876 KB
testcase_14 AC 82 ms
76,932 KB
testcase_15 AC 108 ms
77,692 KB
testcase_16 AC 73 ms
76,720 KB
testcase_17 AC 70 ms
75,948 KB
testcase_18 AC 85 ms
76,964 KB
testcase_19 AC 88 ms
76,848 KB
testcase_20 AC 79 ms
76,784 KB
testcase_21 AC 66 ms
71,400 KB
testcase_22 AC 67 ms
71,236 KB
testcase_23 AC 66 ms
71,272 KB
testcase_24 AC 64 ms
71,456 KB
testcase_25 AC 72 ms
75,932 KB
testcase_26 AC 71 ms
76,180 KB
testcase_27 AC 69 ms
75,752 KB
testcase_28 AC 63 ms
71,460 KB
testcase_29 AC 79 ms
76,424 KB
testcase_30 AC 83 ms
76,948 KB
testcase_31 AC 72 ms
76,432 KB
testcase_32 AC 73 ms
76,736 KB
testcase_33 AC 90 ms
76,572 KB
testcase_34 AC 81 ms
76,776 KB
testcase_35 AC 75 ms
76,756 KB
testcase_36 AC 85 ms
76,848 KB
testcase_37 AC 74 ms
76,684 KB
testcase_38 AC 73 ms
76,928 KB
testcase_39 AC 67 ms
71,324 KB
testcase_40 AC 87 ms
76,824 KB
testcase_41 AC 79 ms
76,460 KB
testcase_42 AC 99 ms
76,984 KB
testcase_43 AC 68 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

ナップザック

dp[]

"""

import sys
from sys import stdin

N,K = map(int,stdin.readline().split())

C = list(map(int,stdin.readline().split()))
D = list(map(int,stdin.readline().split()))

assert 1 <= N <= 1000
assert 1 <= K <= 1000
for i in range(N):
    assert 1 <= C[i] <= 1000
    assert 1 <= D[i] <= 1000
 
mod = 998244353

dpmax = [float("-inf")] * (K+1)
dpcnt = [0] * (K+1)

dpmax[0] = 0
dpcnt[0] = 1

for csum in range(K+1):

    for c,d in zip(C,D):

        if csum+c <= K:

            nexc = csum+c
            nexd = dpmax[csum] + d
            
            if nexd > dpmax[nexc]:
                dpmax[nexc] = nexd
                dpcnt[nexc] = 0

            if nexd == dpmax[nexc]:
                dpcnt[nexc] += dpcnt[csum]
                dpcnt[nexc] %= mod

ans = [0,0]

for i in range(K,-1,-1):

    if dpmax[i] > ans[0]:
        ans = [dpmax[i],0]

    if dpmax[i] == ans[0]:
        ans[1] += dpcnt[i]

print (ans[0])
print (ans[1] % mod)
0