結果

問題 No.527 ナップサック容量問題
ユーザー maspymaspy
提出日時 2020-02-03 12:32:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 534 ms / 2,000 ms
コード長 482 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 42,428 KB
最終ジャッジ日時 2023-10-19 01:42:24
合計ジャッジ時間 22,838 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 512 ms
42,424 KB
testcase_01 AC 499 ms
42,424 KB
testcase_02 AC 510 ms
42,424 KB
testcase_03 AC 509 ms
42,424 KB
testcase_04 AC 504 ms
42,424 KB
testcase_05 AC 505 ms
42,424 KB
testcase_06 AC 513 ms
42,424 KB
testcase_07 AC 511 ms
42,428 KB
testcase_08 AC 513 ms
42,424 KB
testcase_09 AC 503 ms
42,424 KB
testcase_10 AC 534 ms
42,428 KB
testcase_11 AC 516 ms
42,424 KB
testcase_12 AC 513 ms
42,424 KB
testcase_13 AC 522 ms
42,424 KB
testcase_14 AC 520 ms
42,428 KB
testcase_15 AC 512 ms
42,428 KB
testcase_16 AC 520 ms
42,428 KB
testcase_17 AC 520 ms
42,424 KB
testcase_18 AC 521 ms
42,428 KB
testcase_19 AC 515 ms
42,424 KB
testcase_20 AC 504 ms
42,428 KB
testcase_21 AC 520 ms
42,428 KB
testcase_22 AC 519 ms
42,428 KB
testcase_23 AC 511 ms
42,428 KB
testcase_24 AC 510 ms
42,428 KB
testcase_25 AC 507 ms
42,428 KB
testcase_26 AC 509 ms
42,428 KB
testcase_27 AC 510 ms
42,428 KB
testcase_28 AC 501 ms
42,428 KB
testcase_29 AC 520 ms
42,428 KB
testcase_30 AC 508 ms
42,424 KB
testcase_31 AC 505 ms
42,424 KB
testcase_32 AC 513 ms
42,424 KB
testcase_33 AC 518 ms
42,424 KB
testcase_34 AC 505 ms
42,424 KB
testcase_35 AC 509 ms
42,424 KB
testcase_36 AC 501 ms
42,424 KB
testcase_37 AC 506 ms
42,428 KB
testcase_38 AC 507 ms
42,424 KB
testcase_39 AC 512 ms
42,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

*data, = map(int,read().split())
N = data[0]
V = data[1:1+N+N:2]
W = data[2:1+N+N:2]
v_max = data[-1]

# w -> v
dp = np.zeros(10**5+1, np.int64)
for v,w in zip(V,W):
    np.maximum(dp[w:], dp[:-w] + v, out=dp[w:])

np.maximum.accumulate(dp, out=dp)

I = np.where(dp == v_max)[0]
print(max(1, I[0]))
print('inf' if dp[-1] == v_max else I[-1])    
0