結果

問題 No.1037 exhausted
コンテスト
ユーザー norioc
提出日時 2026-11-23 00:54:24
言語 PyPy3
(8.0.1 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 1,004 ms / 2,000 ms
+ 272µs
コード長 887 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 260 ms
コンパイル使用メモリ 64,580 KB
実行使用メモリ 92,384 KB
最終ジャッジ日時 2026-11-23 00:54:40
合計ジャッジ時間 9,532 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def accum_dp(xs: list, f, op, e, init: dict):
    dp = init.copy()
    for x in xs:
        pp = {}
        dp, pp = pp, dp
        for fm_key, fm_val in pp.items():
            for to_key, to_val in f(fm_key, fm_val, x):
                dp[to_key] = op(dp.get(to_key, e), to_val)

    return dp


INF = 1 << 62
N, V, L = map(int, input().split())

xs = []
for _ in range(N):
    x, v, w = map(int, input().split())
    xs.append((x, v, w))
xs.append((L, 0, 0))  # goal

def f(k, v, x):
    # k : (現在位置, 燃料)

    px, fuel = k

    xx, xv, xw = x
    d = xx - px
    if d <= fuel:
        # 補給せず進む
        yield (xx, fuel - d), v

        # 補給する
        nfuel = min(V, fuel - d + xv)
        yield (xx, nfuel), v + xw


init = {(0, V): 0}
dp = accum_dp(xs, f, min, INF, init)

if len(dp) == 0:
    print(-1)
else:
    ans = min(dp.values())
    print(ans)
0