結果
| 問題 |
No.527 ナップサック容量問題
|
| コンテスト | |
| ユーザー |
hanorver
|
| 提出日時 | 2017-06-09 23:08:54 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 835 bytes |
| コンパイル時間 | 376 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 20,640 KB |
| 最終ジャッジ日時 | 2024-09-22 17:50:22 |
| 合計ジャッジ時間 | 18,770 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 2 WA * 12 TLE * 5 -- * 18 |
ソースコード
from collections import defaultdict
n = int(input())
knapsack = defaultdict(list)
for i in range(n):
value, weight = map(int, input().split())
knapsack[weight] += [value]
m = int(input())
weights = [0] * 200000
for weight, value in knapsack.items():
mval = max(value)
for i in range(len(weights) - 1, -1, -1):
if weights[i] != 0:
weights[i + weight] = max(weights[i + weight], weights[i] + mval)
weights[weight] = mval
for i in range(len(weights) - 1):
if weights[i + 1] == 0:
weights[i + 1] = weights[i]
min_weight = 0
high_weight = 0
for i in range(len(weights)):
if weights[i] == m:
if min_weight == 0:
min_weight = i
else:
high_weight = i
if high_weight == 199999:
high_weight = "inf"
print(min_weight)
print(high_weight)
hanorver