結果

問題 No.527 ナップサック容量問題
ユーザー H3PO4H3PO4
提出日時 2020-09-14 09:36:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 618 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 32,844 KB
最終ジャッジ日時 2023-09-04 00:33:41
合計ジャッジ時間 11,263 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
32,704 KB
testcase_01 AC 134 ms
32,824 KB
testcase_02 AC 135 ms
32,664 KB
testcase_03 WA -
testcase_04 AC 131 ms
31,804 KB
testcase_05 AC 170 ms
32,656 KB
testcase_06 AC 215 ms
32,828 KB
testcase_07 AC 197 ms
32,720 KB
testcase_08 AC 162 ms
32,716 KB
testcase_09 AC 128 ms
31,748 KB
testcase_10 AC 213 ms
32,708 KB
testcase_11 AC 188 ms
32,756 KB
testcase_12 AC 171 ms
32,744 KB
testcase_13 AC 216 ms
32,656 KB
testcase_14 AC 158 ms
32,812 KB
testcase_15 AC 176 ms
32,656 KB
testcase_16 AC 132 ms
32,652 KB
testcase_17 AC 178 ms
32,636 KB
testcase_18 AC 179 ms
32,696 KB
testcase_19 WA -
testcase_20 AC 160 ms
32,712 KB
testcase_21 AC 223 ms
32,704 KB
testcase_22 AC 193 ms
32,724 KB
testcase_23 AC 225 ms
32,716 KB
testcase_24 AC 147 ms
32,656 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 189 ms
32,660 KB
testcase_28 WA -
testcase_29 AC 226 ms
32,628 KB
testcase_30 AC 136 ms
32,684 KB
testcase_31 AC 170 ms
32,716 KB
testcase_32 AC 179 ms
32,700 KB
testcase_33 AC 172 ms
32,716 KB
testcase_34 AC 182 ms
32,820 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

N = int(input())
goods = [tuple(map(int, input().split())) for _ in range(N)]
V = int(input())

MAX = 100000
dp = np.zeros(MAX + 1, dtype=int)
ans_min = MAX + 1
ans_max = 0
for v, w in goods:
    new_dp = dp.copy()
    new_dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
    dp = new_dp

    l = np.searchsorted(dp, V, side='left')
    if 0 <= l <= MAX and dp[l] == V:
        ans_min = min(ans_min, l)

    r = np.searchsorted(dp, V, side='right') - 1
    if 0 <= r <= MAX and dp[r] == V:
        ans_max = max(ans_max, r)

print(ans_min if ans_min > 0 else 1)
print(ans_max if ans_max < MAX else 'inf')
0