結果

問題 No.527 ナップサック容量問題
ユーザー kurimupykurimupy
提出日時 2020-06-21 01:44:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 366 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 355 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 155,076 KB
最終ジャッジ日時 2023-09-16 17:58:45
合計ジャッジ時間 9,374 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
79,012 KB
testcase_01 AC 90 ms
79,992 KB
testcase_02 AC 81 ms
78,416 KB
testcase_03 AC 94 ms
80,040 KB
testcase_04 AC 78 ms
77,864 KB
testcase_05 AC 169 ms
108,404 KB
testcase_06 AC 263 ms
143,552 KB
testcase_07 AC 278 ms
130,348 KB
testcase_08 AC 185 ms
103,580 KB
testcase_09 AC 79 ms
77,700 KB
testcase_10 AC 332 ms
144,364 KB
testcase_11 AC 213 ms
123,956 KB
testcase_12 AC 175 ms
110,768 KB
testcase_13 AC 270 ms
145,920 KB
testcase_14 AC 147 ms
101,184 KB
testcase_15 AC 187 ms
116,156 KB
testcase_16 AC 90 ms
80,096 KB
testcase_17 AC 168 ms
109,176 KB
testcase_18 AC 178 ms
113,920 KB
testcase_19 AC 97 ms
80,640 KB
testcase_20 AC 152 ms
102,772 KB
testcase_21 AC 292 ms
155,076 KB
testcase_22 AC 221 ms
128,752 KB
testcase_23 AC 286 ms
152,948 KB
testcase_24 AC 129 ms
91,808 KB
testcase_25 AC 221 ms
127,208 KB
testcase_26 AC 205 ms
121,416 KB
testcase_27 AC 251 ms
122,384 KB
testcase_28 AC 194 ms
116,132 KB
testcase_29 AC 366 ms
154,720 KB
testcase_30 AC 98 ms
84,040 KB
testcase_31 AC 164 ms
109,804 KB
testcase_32 AC 187 ms
117,604 KB
testcase_33 AC 169 ms
111,400 KB
testcase_34 AC 189 ms
119,032 KB
testcase_35 AC 195 ms
119,256 KB
testcase_36 AC 86 ms
79,228 KB
testcase_37 AC 199 ms
108,484 KB
testcase_38 AC 191 ms
117,052 KB
testcase_39 AC 177 ms
113,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# フツーの01なっぷさっく
N = int(input())
que = [tuple(map(int, input().split())) for i in range(N)]
V = int(input())
# dp[X][W] = X番目までの荷物を使って ちょうど重さWで実現できる最大の価値
dp = [[0 for i in range(10**5+1)] for j in range(N+1)]
for i in range(N):
    value, weight = que[i]
    for j in range(10**5+1):
        if j >= weight:
            dp[i+1][j] = max(dp[i+1][j],dp[i][j], dp[i][j-weight]+value)
        else:
            dp[i+1][j]=max(dp[i+1][j],dp[i][j])

wanted = dp[N]
mini = 1
for i in range(1,10**5+1):
    if wanted[i] == V:
        mini = i
        break
maxi = mini
for i in range(mini,10**5+1):
    if wanted[i] == V:
        maxi = i

value_max=0
for value,weight in que:
    value_max+=value
if value_max==wanted[maxi]:
    maxi="inf"
print(mini)
print(maxi)
0