結果

問題 No.527 ナップサック容量問題
ユーザー brthyyjpbrthyyjp
提出日時 2022-03-02 13:25:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 516 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 76,856 KB
最終ジャッジ日時 2023-09-23 06:49:01
合計ジャッジ時間 5,822 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,072 KB
testcase_01 AC 76 ms
71,068 KB
testcase_02 AC 77 ms
71,092 KB
testcase_03 WA -
testcase_04 AC 77 ms
71,356 KB
testcase_05 AC 96 ms
76,572 KB
testcase_06 AC 117 ms
76,760 KB
testcase_07 WA -
testcase_08 AC 93 ms
76,308 KB
testcase_09 AC 78 ms
71,404 KB
testcase_10 WA -
testcase_11 AC 102 ms
76,656 KB
testcase_12 AC 94 ms
76,836 KB
testcase_13 AC 112 ms
76,752 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 78 ms
71,320 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 77 ms
71,012 KB
testcase_29 WA -
testcase_30 AC 84 ms
75,964 KB
testcase_31 AC 93 ms
76,576 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 86 ms
75,880 KB
testcase_36 AC 77 ms
71,168 KB
testcase_37 AC 84 ms
76,020 KB
testcase_38 AC 85 ms
75,944 KB
testcase_39 AC 82 ms
76,036 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)
for i in reversed(range(u+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