結果

問題 No.1037 exhausted
ユーザー tcltktcltk
提出日時 2021-01-18 00:56:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 767 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 121,216 KB
最終ジャッジ日時 2024-05-07 14:27:08
合計ジャッジ時間 5,173 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 121 ms
88,840 KB
testcase_03 AC 121 ms
89,088 KB
testcase_04 WA -
testcase_05 AC 125 ms
88,784 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 219 ms
105,344 KB
testcase_13 AC 217 ms
105,344 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 128 ms
88,960 KB
testcase_21 AC 124 ms
89,104 KB
testcase_22 AC 127 ms
89,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
from queue import PriorityQueue
import bisect
import heapq

def input():
    return sys.stdin.readline()[:-1]

sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """3 5 10
# 2 4 2
# 3 3 3
# 8 2 4
# """
# sys.stdin = io.StringIO(_INPUT)



def main():
    N, V, L = map(int, input().split())
    x = [None for _ in range(N)] + [L]
    v = [None for _ in range(N)]
    w = [None for _ in range(N)]
    for i in range(N):
        x[i], v[i], w[i] = map(int, input().split())
        if i >= 1 and x[i] - x[i-1] > V:
            print(-1)
            return

    dp = [[10**10 for _ in range(V+1)] for _ in range(N+1)]
    dp[0][V-x[0]] = 0
    for i in range(N):
        d = x[i+1] - x[i]
        for v in range(V+1):
            if dp[i][v] < 10**10:
                if v-(x[i+1]-x[i]) >= 0:
                    dp[i+1][v-d] = min(dp[i+1][v-d], dp[i][v])
                dp[i+1][V-d] = min(dp[i+1][V-d], dp[i][v] + w[i])

    MinW = min(dp[N])
    if MinW == 10**10:
        print(-1)
    else:
        print(MinW)

if __name__ == '__main__':
    main()
0