結果

問題 No.2232 Miser's Gift
ユーザー chankei271828chankei271828
提出日時 2023-03-04 13:18:03
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 980 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 236,940 KB
最終ジャッジ日時 2023-10-18 04:32:24
合計ジャッジ時間 29,599 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
55,488 KB
testcase_01 AC 42 ms
55,488 KB
testcase_02 AC 42 ms
55,488 KB
testcase_03 AC 151 ms
85,100 KB
testcase_04 AC 1,199 ms
215,856 KB
testcase_05 AC 66 ms
70,796 KB
testcase_06 AC 42 ms
55,488 KB
testcase_07 AC 75 ms
81,844 KB
testcase_08 AC 92 ms
82,504 KB
testcase_09 AC 94 ms
82,504 KB
testcase_10 AC 93 ms
82,504 KB
testcase_11 AC 94 ms
82,504 KB
testcase_12 AC 96 ms
82,504 KB
testcase_13 AC 179 ms
85,384 KB
testcase_14 AC 179 ms
85,740 KB
testcase_15 AC 175 ms
85,340 KB
testcase_16 AC 174 ms
85,892 KB
testcase_17 AC 180 ms
85,680 KB
testcase_18 AC 182 ms
85,884 KB
testcase_19 AC 176 ms
85,596 KB
testcase_20 AC 169 ms
85,568 KB
testcase_21 AC 176 ms
85,732 KB
testcase_22 AC 175 ms
85,608 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 1,467 ms
183,212 KB
testcase_29 AC 1,374 ms
178,636 KB
testcase_30 AC 1,375 ms
179,332 KB
testcase_31 AC 1,419 ms
179,428 KB
testcase_32 AC 1,398 ms
184,576 KB
testcase_33 AC 296 ms
97,752 KB
testcase_34 AC 318 ms
99,136 KB
testcase_35 AC 300 ms
97,640 KB
testcase_36 AC 272 ms
94,312 KB
testcase_37 AC 318 ms
97,436 KB
testcase_38 AC 124 ms
76,400 KB
testcase_39 AC 125 ms
76,416 KB
testcase_40 AC 123 ms
76,368 KB
testcase_41 AC 124 ms
76,528 KB
testcase_42 AC 124 ms
76,548 KB
testcase_43 AC 126 ms
76,396 KB
testcase_44 AC 123 ms
76,368 KB
testcase_45 AC 124 ms
76,400 KB
testcase_46 AC 128 ms
76,440 KB
testcase_47 AC 130 ms
76,452 KB
testcase_48 AC 71 ms
70,568 KB
testcase_49 AC 69 ms
70,508 KB
testcase_50 AC 67 ms
68,432 KB
testcase_51 AC 68 ms
70,492 KB
testcase_52 AC 70 ms
70,524 KB
testcase_53 AC 68 ms
70,484 KB
testcase_54 AC 73 ms
70,520 KB
testcase_55 AC 68 ms
70,492 KB
testcase_56 AC 69 ms
70,516 KB
testcase_57 AC 69 ms
70,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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