結果

問題 No.1037 exhausted
ユーザー KodaiKodai
提出日時 2020-04-28 00:12:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 27,188 KB
最終ジャッジ日時 2024-05-02 05:38:35
合計ジャッジ時間 4,396 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
16,256 KB
testcase_01 AC 33 ms
10,880 KB
testcase_02 AC 30 ms
10,880 KB
testcase_03 WA -
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 32 ms
10,880 KB
testcase_06 WA -
testcase_07 AC 31 ms
10,880 KB
testcase_08 AC 30 ms
10,880 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 30 ms
10,880 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

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