結果

問題 No.527 ナップサック容量問題
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-02 13:24:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 453 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 77,200 KB
最終ジャッジ日時 2023-09-23 06:48:07
合計ジャッジ時間 5,636 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,076 KB
testcase_01 AC 76 ms
71,524 KB
testcase_02 AC 73 ms
71,392 KB
testcase_03 WA -
testcase_04 AC 78 ms
71,428 KB
testcase_05 AC 88 ms
76,708 KB
testcase_06 AC 107 ms
76,972 KB
testcase_07 WA -
testcase_08 AC 86 ms
76,232 KB
testcase_09 AC 71 ms
71,292 KB
testcase_10 WA -
testcase_11 AC 92 ms
76,812 KB
testcase_12 AC 88 ms
76,596 KB
testcase_13 AC 106 ms
76,848 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 75 ms
71,396 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 73 ms
71,548 KB
testcase_29 WA -
testcase_30 AC 82 ms
76,064 KB
testcase_31 AC 87 ms
76,208 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 84 ms
75,972 KB
testcase_36 AC 77 ms
71,352 KB
testcase_37 AC 84 ms
76,064 KB
testcase_38 AC 84 ms
76,304 KB
testcase_39 AC 85 ms
75,884 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
dp = [INF]*(u+2)
dp[0] = 0
for v, w in zip(V, W):
    for i in reversed(range(u+2)):
        if i+v <= u+1:
            dp[i+v] = min(dp[i+v], dp[i]+w)
if dp[u+1] != INF:
    print(dp[u])
    print(dp[u+1]-1)
else:
    print(dp[u])
    print('inf')
0