結果

問題 No.1037 exhausted
コンテスト
ユーザー Kodai
提出日時 2020-04-28 16:43:49
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 1,680 ms / 2,000 ms
+ 590µs
コード長 932 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 55 ms
コンパイル使用メモリ 14,720 KB
実行使用メモリ 43,904 KB
最終ジャッジ日時 2026-10-15 17:29:00
合計ジャッジ時間 15,350 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
sys.setrecursionlimit(10**6)

N, V, L = list(map(int, input().split()))
shop_list = [list(map(int, input().split())) for i in range(N)]
dis_list = [shop_list[0][0]] + [(shop_list[i + 1][0] - shop_list[i][0])
                                for i in range(len(shop_list) - 1)] + [L - shop_list[-1][0]]

dp_list = [[-2 for i in range(V + 1)] for i in range(N + 1)]


def solve(i, j):

    j -= dis_list[i]
    if j < 0:
        return -1

    if i == N:
        return 0
    if dp_list[i][j] != -2:
        return dp_list[i][j]

    a = solve(i + 1, j)
    b = solve(i + 1, j + shop_list[i][1] if j + shop_list[i][1] < V else V)

    if a == -1 and b == -1:
        dp_list[i][j] = -1
        return -1
    elif a == -1:
        res = b + shop_list[i][2]
        dp_list[i][j] = res
        return res
    else:
        res = min([a, b + shop_list[i][2]])
        dp_list[i][j] = res
        return res


print(solve(0, V))
0