結果

問題 No.527 ナップサック容量問題
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-02 13:30:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 539 bytes
コンパイル時間 327 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 77,660 KB
最終ジャッジ日時 2023-09-23 06:51:35
合計ジャッジ時間 6,726 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
76,616 KB
testcase_01 AC 73 ms
71,496 KB
testcase_02 AC 83 ms
76,956 KB
testcase_03 AC 86 ms
76,752 KB
testcase_04 AC 74 ms
71,448 KB
testcase_05 AC 111 ms
77,660 KB
testcase_06 AC 142 ms
77,288 KB
testcase_07 AC 132 ms
77,584 KB
testcase_08 AC 109 ms
77,372 KB
testcase_09 AC 83 ms
76,652 KB
testcase_10 AC 144 ms
77,208 KB
testcase_11 AC 125 ms
77,256 KB
testcase_12 AC 116 ms
77,348 KB
testcase_13 AC 141 ms
77,164 KB
testcase_14 AC 107 ms
77,492 KB
testcase_15 AC 120 ms
77,564 KB
testcase_16 AC 87 ms
76,708 KB
testcase_17 AC 110 ms
77,340 KB
testcase_18 AC 116 ms
77,588 KB
testcase_19 AC 87 ms
76,964 KB
testcase_20 AC 109 ms
77,564 KB
testcase_21 AC 149 ms
76,992 KB
testcase_22 AC 128 ms
77,496 KB
testcase_23 AC 146 ms
77,168 KB
testcase_24 AC 97 ms
77,300 KB
testcase_25 AC 74 ms
71,456 KB
testcase_26 AC 122 ms
77,600 KB
testcase_27 AC 121 ms
77,312 KB
testcase_28 AC 74 ms
71,404 KB
testcase_29 AC 150 ms
77,300 KB
testcase_30 AC 90 ms
77,016 KB
testcase_31 AC 112 ms
77,608 KB
testcase_32 AC 119 ms
77,560 KB
testcase_33 AC 114 ms
77,340 KB
testcase_34 AC 120 ms
77,488 KB
testcase_35 AC 116 ms
77,360 KB
testcase_36 AC 81 ms
71,188 KB
testcase_37 AC 109 ms
77,484 KB
testcase_38 AC 114 ms
77,088 KB
testcase_39 AC 111 ms
77,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
V = []
W = []
for i in range(n):
    v, w = map(int, input().split())
    V.append(v)
    W.append(w)
u = int(input())
if u == 0:
    print(1)
    print(min(W)-1)
    exit()
INF = 10**18
maxv = 10**5+1
dp = [INF]*(maxv+1)
dp[0] = 0
for v, w in zip(V, W):
    for i in reversed(range(maxv)):
        if i+v <= maxv:
            dp[i+v] = min(dp[i+v], dp[i]+w)
for i in reversed(range(maxv-1)):
    dp[i] = min(dp[i], dp[i+1])
if dp[u+1] != INF:
    print(dp[u])
    print(dp[u+1]-1)
else:
    print(dp[u])
    print('inf')
0