結果

問題 No.2232 Miser's Gift
ユーザー chankei271828chankei271828
提出日時 2023-03-03 23:05:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 949 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,640 KB
実行使用メモリ 237,704 KB
最終ジャッジ日時 2023-10-18 03:25:13
合計ジャッジ時間 29,377 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,484 KB
testcase_01 AC 43 ms
55,484 KB
testcase_02 AC 44 ms
55,484 KB
testcase_03 AC 152 ms
84,492 KB
testcase_04 AC 1,227 ms
214,924 KB
testcase_05 AC 67 ms
70,772 KB
testcase_06 AC 43 ms
55,484 KB
testcase_07 AC 78 ms
81,804 KB
testcase_08 AC 94 ms
82,456 KB
testcase_09 AC 93 ms
82,516 KB
testcase_10 AC 93 ms
82,456 KB
testcase_11 AC 94 ms
82,456 KB
testcase_12 AC 94 ms
82,452 KB
testcase_13 AC 176 ms
85,540 KB
testcase_14 AC 182 ms
85,788 KB
testcase_15 AC 177 ms
85,504 KB
testcase_16 AC 176 ms
85,616 KB
testcase_17 AC 184 ms
85,516 KB
testcase_18 AC 187 ms
86,128 KB
testcase_19 AC 182 ms
85,796 KB
testcase_20 AC 174 ms
85,460 KB
testcase_21 AC 180 ms
85,676 KB
testcase_22 AC 179 ms
85,700 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 1,448 ms
183,124 KB
testcase_29 AC 1,461 ms
177,172 KB
testcase_30 AC 1,424 ms
181,132 KB
testcase_31 AC 1,458 ms
177,668 KB
testcase_32 AC 1,432 ms
186,544 KB
testcase_33 AC 309 ms
98,880 KB
testcase_34 AC 311 ms
99,360 KB
testcase_35 AC 312 ms
97,520 KB
testcase_36 AC 282 ms
95,040 KB
testcase_37 AC 302 ms
97,160 KB
testcase_38 AC 125 ms
76,496 KB
testcase_39 AC 127 ms
76,388 KB
testcase_40 AC 126 ms
76,356 KB
testcase_41 AC 128 ms
76,516 KB
testcase_42 AC 125 ms
76,388 KB
testcase_43 AC 125 ms
76,368 KB
testcase_44 AC 127 ms
76,432 KB
testcase_45 AC 127 ms
76,440 KB
testcase_46 AC 131 ms
76,928 KB
testcase_47 AC 131 ms
77,092 KB
testcase_48 AC 73 ms
72,536 KB
testcase_49 AC 68 ms
70,476 KB
testcase_50 AC 68 ms
70,468 KB
testcase_51 AC 67 ms
70,452 KB
testcase_52 AC 69 ms
70,472 KB
testcase_53 AC 69 ms
70,468 KB
testcase_54 AC 73 ms
72,536 KB
testcase_55 AC 69 ms
70,448 KB
testcase_56 AC 71 ms
70,476 KB
testcase_57 AC 70 ms
70,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque,defaultdict
N,W=map(int,input().split())
pre=[tuple(map(int,input().split())) for _ in range(N)]
dp=dict()
#dp[i][j]:i番目の品物までで、重さjになる組み合わせの中での勝ちの総和の最大値
#配る
d=deque()
d.append(0)
dp[0]=0
A=10**5+5
while d:
    n=d.popleft()
    i,j=divmod(n,A)
    if i==N:
        break
    now=dp.pop(n)
    if (i+1)*A+j not in dp:
        dp[(i+1)*A+j]=0
        d.append((i+1)*A+j)
    dp[(i+1)*A+j]=max(now,dp[(i+1)*A+j])
    w,v=pre[i]
    if j+w<=W:
        if (i+1)*A+j+w not in dp:
            dp[(i+1)*A+j+w]=0
            d.append((i+1)*A+j+w)
        dp[(i+1)*A+j+w]=max(now+v,dp[(i+1)*A+j+w])
ans=[]
for j in range(W+1):
    if j==0:
        ans.append(0)
    else:
        if N*A+j not in dp:
            ans.append(ans[-1])
        else:
            ans.append(max(dp[N*A+j],ans[-1]))
ans_now=ans[W]
for X in range(1,W+1):
    print(ans_now-(ans[W-X])+1)
0