結果

問題 No.527 ナップサック容量問題
ユーザー hedwig100hedwig100
提出日時 2020-05-26 20:17:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 522 ms / 2,000 ms
コード長 441 bytes
コンパイル時間 399 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 45,160 KB
最終ジャッジ日時 2024-04-21 04:32:46
合計ジャッジ時間 21,940 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 488 ms
44,888 KB
testcase_01 AC 482 ms
44,336 KB
testcase_02 AC 491 ms
44,520 KB
testcase_03 AC 484 ms
44,920 KB
testcase_04 AC 479 ms
43,952 KB
testcase_05 AC 487 ms
44,768 KB
testcase_06 AC 501 ms
44,516 KB
testcase_07 AC 504 ms
44,780 KB
testcase_08 AC 492 ms
44,760 KB
testcase_09 AC 488 ms
44,460 KB
testcase_10 AC 505 ms
44,892 KB
testcase_11 AC 495 ms
44,764 KB
testcase_12 AC 496 ms
44,524 KB
testcase_13 AC 505 ms
45,020 KB
testcase_14 AC 490 ms
44,888 KB
testcase_15 AC 502 ms
45,156 KB
testcase_16 AC 495 ms
45,144 KB
testcase_17 AC 500 ms
44,524 KB
testcase_18 AC 495 ms
44,652 KB
testcase_19 AC 495 ms
44,920 KB
testcase_20 AC 500 ms
44,920 KB
testcase_21 AC 510 ms
45,160 KB
testcase_22 AC 510 ms
44,892 KB
testcase_23 AC 510 ms
44,640 KB
testcase_24 AC 497 ms
44,892 KB
testcase_25 AC 481 ms
43,988 KB
testcase_26 AC 510 ms
44,764 KB
testcase_27 AC 503 ms
44,652 KB
testcase_28 AC 487 ms
44,332 KB
testcase_29 AC 510 ms
45,148 KB
testcase_30 AC 492 ms
44,888 KB
testcase_31 AC 497 ms
44,912 KB
testcase_32 AC 508 ms
44,520 KB
testcase_33 AC 497 ms
44,628 KB
testcase_34 AC 522 ms
44,648 KB
testcase_35 AC 506 ms
45,032 KB
testcase_36 AC 492 ms
43,948 KB
testcase_37 AC 494 ms
44,900 KB
testcase_38 AC 498 ms
44,764 KB
testcase_39 AC 503 ms
44,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
INF = 10 ** 10

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

if V == 0:
    ans = 1,min(w for v,w in item) - 1
else:
    dp = np.zeros(100005,np.int64)
    dp[1:] = INF
    for v,w in item:
        dp[v:] = np.minimum(dp[v:],dp[:-v] + w)

    X = dp[V + 1:].min()
    if X == INF:
        ans = dp[V],'inf'
    else:
        ans = dp[V],X - 1
print('\n'.join(map(str,ans)))
0