結果

問題 No.2232 Miser's Gift
ユーザー chankei271828chankei271828
提出日時 2023-03-03 23:11:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 944 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 237,720 KB
最終ジャッジ日時 2023-10-18 03:29:59
合計ジャッジ時間 29,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,500 KB
testcase_01 AC 43 ms
55,500 KB
testcase_02 AC 43 ms
55,500 KB
testcase_03 AC 153 ms
84,488 KB
testcase_04 AC 1,250 ms
214,932 KB
testcase_05 AC 67 ms
70,772 KB
testcase_06 AC 42 ms
55,500 KB
testcase_07 AC 77 ms
81,804 KB
testcase_08 AC 98 ms
82,460 KB
testcase_09 AC 93 ms
82,460 KB
testcase_10 AC 95 ms
82,460 KB
testcase_11 AC 93 ms
82,460 KB
testcase_12 AC 94 ms
82,460 KB
testcase_13 AC 177 ms
85,112 KB
testcase_14 AC 183 ms
85,904 KB
testcase_15 AC 181 ms
85,536 KB
testcase_16 AC 179 ms
85,488 KB
testcase_17 AC 186 ms
85,536 KB
testcase_18 AC 184 ms
85,808 KB
testcase_19 AC 186 ms
85,536 KB
testcase_20 AC 172 ms
85,340 KB
testcase_21 AC 181 ms
85,664 KB
testcase_22 AC 182 ms
85,628 KB
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 1,409 ms
183,080 KB
testcase_29 AC 1,371 ms
177,020 KB
testcase_30 AC 1,364 ms
179,636 KB
testcase_31 AC 1,451 ms
177,632 KB
testcase_32 AC 1,441 ms
186,820 KB
testcase_33 AC 307 ms
98,792 KB
testcase_34 AC 317 ms
98,984 KB
testcase_35 AC 307 ms
97,428 KB
testcase_36 AC 279 ms
95,132 KB
testcase_37 AC 304 ms
97,168 KB
testcase_38 AC 126 ms
76,480 KB
testcase_39 AC 128 ms
76,380 KB
testcase_40 AC 124 ms
76,364 KB
testcase_41 AC 128 ms
76,504 KB
testcase_42 AC 125 ms
76,384 KB
testcase_43 AC 125 ms
76,364 KB
testcase_44 AC 129 ms
76,492 KB
testcase_45 AC 127 ms
76,376 KB
testcase_46 AC 132 ms
76,924 KB
testcase_47 AC 129 ms
76,944 KB
testcase_48 AC 71 ms
72,596 KB
testcase_49 AC 68 ms
70,472 KB
testcase_50 AC 68 ms
70,468 KB
testcase_51 AC 68 ms
70,452 KB
testcase_52 AC 68 ms
70,472 KB
testcase_53 AC 69 ms
70,468 KB
testcase_54 AC 73 ms
72,532 KB
testcase_55 AC 69 ms
70,444 KB
testcase_56 AC 71 ms
70,476 KB
testcase_57 AC 69 ms
70,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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