結果

問題 No.527 ナップサック容量問題
ユーザー roarisroaris
提出日時 2019-08-26 16:31:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 91,904 KB
最終ジャッジ日時 2024-04-25 08:33:52
合計ジャッジ時間 4,540 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,096 KB
testcase_01 AC 44 ms
51,840 KB
testcase_02 AC 42 ms
51,840 KB
testcase_03 AC 59 ms
61,568 KB
testcase_04 AC 43 ms
51,968 KB
testcase_05 AC 79 ms
70,272 KB
testcase_06 AC 146 ms
90,624 KB
testcase_07 AC 90 ms
73,088 KB
testcase_08 AC 76 ms
68,096 KB
testcase_09 AC 44 ms
52,096 KB
testcase_10 AC 131 ms
91,904 KB
testcase_11 AC 92 ms
76,672 KB
testcase_12 AC 82 ms
70,912 KB
testcase_13 AC 120 ms
89,728 KB
testcase_14 AC 68 ms
66,048 KB
testcase_15 AC 78 ms
69,248 KB
testcase_16 AC 57 ms
61,440 KB
testcase_17 AC 75 ms
69,760 KB
testcase_18 AC 87 ms
72,704 KB
testcase_19 AC 57 ms
61,952 KB
testcase_20 AC 66 ms
64,384 KB
testcase_21 AC 74 ms
68,864 KB
testcase_22 AC 73 ms
65,664 KB
testcase_23 AC 70 ms
67,072 KB
testcase_24 AC 63 ms
63,616 KB
testcase_25 AC 42 ms
52,224 KB
testcase_26 AC 67 ms
64,000 KB
testcase_27 AC 59 ms
61,824 KB
testcase_28 AC 43 ms
52,352 KB
testcase_29 AC 68 ms
64,768 KB
testcase_30 AC 62 ms
62,720 KB
testcase_31 AC 77 ms
68,736 KB
testcase_32 AC 98 ms
75,136 KB
testcase_33 AC 82 ms
70,912 KB
testcase_34 AC 82 ms
70,144 KB
testcase_35 AC 57 ms
60,544 KB
testcase_36 AC 44 ms
51,840 KB
testcase_37 AC 52 ms
59,648 KB
testcase_38 AC 57 ms
60,160 KB
testcase_39 AC 53 ms
60,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
vw = [tuple(map(int, input().split())) for _ in range(N)]
V = int(input())
dp = [[10**18 for _ in range(V+2)] for _ in range(N+1)]
dp[0][0] = 0

for i in range(N):
    vi, wi = vw[i]
    
    for j in range(V+2):
        if j - vi >= 0:
            dp[i+1][j] = min(dp[i][j-vi] + wi, dp[i][j])
        else:
            dp[i+1][j] = min(dp[i][0] + wi, dp[i][j])

minV = max(1, dp[N][V])
maxV = dp[N][V+1]

if maxV == 10 ** 18:
    maxV = 'inf'
else:
    maxV -= 1

print(minV)
print(maxV)
0