結果

問題 No.1037 exhausted
ユーザー KodaiKodai
提出日時 2020-04-28 01:34:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 889 bytes
コンパイル時間 131 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 313,592 KB
最終ジャッジ日時 2024-05-02 07:23:57
合計ジャッジ時間 4,075 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
16,384 KB
testcase_01 AC 26 ms
10,624 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 27 ms
10,624 KB
testcase_04 AC 28 ms
10,752 KB
testcase_05 AC 26 ms
10,752 KB
testcase_06 AC 26 ms
10,752 KB
testcase_07 AC 27 ms
10,624 KB
testcase_08 AC 26 ms
10,880 KB
testcase_09 AC 26 ms
10,624 KB
testcase_10 AC 25 ms
10,880 KB
testcase_11 AC 29 ms
10,752 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)]
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_dict = {}


def solve(i, j):

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

    if i == N:
        return 0
    if (i, j) in dp_dict:
        return dp_dict[(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_dict[(i, j)] = -1
        return -1
    elif a == -1:
        res = b + shop_list[i][2]
        dp_dict[(i, j)] = res
        return res
    else:
        res = min([a, b + shop_list[i][2]])
        dp_dict[(i, j)] = res
        return res


print(solve(0, V))
0