結果

問題 No.1037 exhausted
ユーザー maspymaspy
提出日時 2020-04-24 21:39:56
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 589 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 103 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 44,520 KB
最終ジャッジ日時 2024-04-23 03:03:43
合計ジャッジ時間 14,750 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 538 ms
43,996 KB
testcase_01 AC 528 ms
44,104 KB
testcase_02 AC 529 ms
44,516 KB
testcase_03 AC 535 ms
44,516 KB
testcase_04 AC 534 ms
44,516 KB
testcase_05 AC 534 ms
44,256 KB
testcase_06 AC 529 ms
44,380 KB
testcase_07 AC 531 ms
44,012 KB
testcase_08 AC 541 ms
44,384 KB
testcase_09 AC 533 ms
44,000 KB
testcase_10 AC 544 ms
44,388 KB
testcase_11 AC 534 ms
44,124 KB
testcase_12 AC 580 ms
44,132 KB
testcase_13 AC 581 ms
44,132 KB
testcase_14 AC 589 ms
44,264 KB
testcase_15 AC 586 ms
44,520 KB
testcase_16 AC 573 ms
44,380 KB
testcase_17 AC 583 ms
44,380 KB
testcase_18 AC 573 ms
44,516 KB
testcase_19 AC 580 ms
44,000 KB
testcase_20 AC 538 ms
44,132 KB
testcase_21 AC 539 ms
43,880 KB
testcase_22 AC 537 ms
44,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N, V, L = map(int, readline().split())
m = map(int, read().split())

INF = 10 ** 15

dp = np.zeros(V + 1, np.int64)
now_x = 0
for x, v, w in zip(m, m, m):
    dx = x - now_x
    now_x = x
    if dx > V:
        print(-1)
        exit()
    newdp = np.full_like(dp, INF)
    # まず、使う
    dp = dp[dx:]
    # 買わない場合
    np.minimum(dp, newdp[: len(dp)], out=newdp[: len(dp)])
    # 買う場合
    if v > V:
        v = V
    n = min(V - v, len(dp) - 1)
    np.minimum(dp[: n + 1] + w, newdp[v: n + v + 1], out=newdp[v: n + v + 1])
    # あふれるほど買う
    if len(dp) > V - v:
        x = dp[V - v:].min() + w
        if newdp[-1] > x:
            newdp[-1] = x
    dp = newdp

dx = L - now_x
if dx > V:
    print(-1)
    exit()

dp = dp[dx:]
x = dp.min()
if x >= INF:
    x = -1
print(x)
0