結果

問題 No.527 ナップサック容量問題
ユーザー hedwig100hedwig100
提出日時 2020-05-26 19:58:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 448 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,340 KB
最終ジャッジ日時 2024-04-21 04:27:48
合計ジャッジ時間 21,444 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 487 ms
43,692 KB
testcase_01 AC 488 ms
43,564 KB
testcase_02 AC 492 ms
43,588 KB
testcase_03 WA -
testcase_04 AC 486 ms
43,696 KB
testcase_05 AC 486 ms
43,820 KB
testcase_06 AC 489 ms
44,212 KB
testcase_07 WA -
testcase_08 AC 492 ms
43,584 KB
testcase_09 AC 482 ms
43,956 KB
testcase_10 WA -
testcase_11 AC 485 ms
43,592 KB
testcase_12 AC 487 ms
43,568 KB
testcase_13 AC 477 ms
43,560 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 522 ms
44,336 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 485 ms
43,796 KB
testcase_29 WA -
testcase_30 AC 485 ms
44,084 KB
testcase_31 AC 482 ms
44,332 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 474 ms
43,560 KB
testcase_36 AC 492 ms
43,820 KB
testcase_37 AC 487 ms
43,948 KB
testcase_38 AC 493 ms
43,816 KB
testcase_39 AC 483 ms
43,956 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 == sum(v for v,w in item):
    print(sum(w for v,w in item))
    print('inf')
    exit()
dp = np.zeros(V + 2,np.int64)
dp[1:] = INF
for v,w in item:
    dp[v:] = np.minimum(dp[v:],dp[:-v] + w)

if dp[-2] == 0:
    ans = 1,min(w for v,w in item) - 1
else:
    ans = dp[-2],dp[-1] - 1
print('\n'.join(map(str,ans))) 
0