結果

問題 No.1037 exhausted
ユーザー Kodai
提出日時 2020-04-28 00:12:23
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 57,188 KB
最終ジャッジ日時 2024-11-22 16:44:00
合計ジャッジ時間 25,792 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 6 TLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

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)]

dp_dict = {}


def solve(i, j):
    if j < 0:
        return -1

    if (i, j) in dp_dict:
        return dp_dict[(i, j)]

    if i == N - 1:
        dis = L - shop_list[i][0]
        if j >= dis:
            dp_dict[(i, j)] = 0
            return 0
        elif j + shop_list[i][1] if j + shop_list[i][1] < V else V >= dis:
            dp_dict[(i, j)] = shop_list[i][2]
            return shop_list[i][2]
        else:
            dp_dict[(i, j)] = -1
            return -1

    dis = shop_list[i + 1][0] - shop_list[i][0]
    a = solve(i + 1, j - dis)
    j += shop_list[i][1]
    if j > V:
        j = V
    b = solve(i + 1, j - dis) + shop_list[i][2]

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


if V - shop_list[0][0] < 0:
    print(-1)
else:
    print(solve(0, V - shop_list[0][0]))
0