結果

問題 No.1037 exhausted
ユーザー convexineqconvexineq
提出日時 2020-04-24 22:31:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 1,987 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,828 KB
実行使用メモリ 77,220 KB
最終ジャッジ日時 2024-04-23 03:39:49
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
54,620 KB
testcase_01 AC 41 ms
54,692 KB
testcase_02 AC 41 ms
53,996 KB
testcase_03 AC 42 ms
55,896 KB
testcase_04 AC 46 ms
54,340 KB
testcase_05 AC 41 ms
54,544 KB
testcase_06 AC 41 ms
54,692 KB
testcase_07 AC 40 ms
54,504 KB
testcase_08 AC 39 ms
55,028 KB
testcase_09 AC 44 ms
54,988 KB
testcase_10 AC 42 ms
55,068 KB
testcase_11 AC 44 ms
54,780 KB
testcase_12 AC 115 ms
77,020 KB
testcase_13 AC 117 ms
76,960 KB
testcase_14 AC 111 ms
76,912 KB
testcase_15 AC 112 ms
77,004 KB
testcase_16 AC 108 ms
77,056 KB
testcase_17 AC 112 ms
77,220 KB
testcase_18 AC 114 ms
77,052 KB
testcase_19 AC 109 ms
76,852 KB
testcase_20 AC 110 ms
77,088 KB
testcase_21 AC 107 ms
77,000 KB
testcase_22 AC 100 ms
76,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""
sliding window aggrigation
モノイドのqueueを管理する
fold_all: すべてをたたみこむ
popleft
append
"""
from itertools import accumulate
from collections import deque
class SWAG:
    def __init__(self, operator_M, e_M):
        self.op_M = operator_M
        self.op_rev = lambda x,y: self.op_M(y,x)
        self.e_M = e_M
        self.q = deque([])
        self.accL = []
        self.accR = e_M
        self.L = self.R = 0

    def build(self,lst):
        self.q = deque(lst)
        self.L = len(lst)
        self.accL = list(accumulate(reversed(lst),self.op_rev))

    def __len__(self):
        return self.L + self.R

    def fold_all(self):
        if self.L: return self.op_M(self.accL[-1],self.accR)
        else: return self.accR

    def append(self,x):
        self.q.append(x)
        self.accR = self.op_M(self.accR,x)
        self.R += 1
    
    def popleft(self):
        if self.L:
            self.accL.pop()
            self.L -= 1
            return self.q.popleft()
        elif self.R:
            v = self.q.popleft()
            self.L,self.R = self.R-1,0
            self.accL = list(accumulate(reversed(self.q),self.op_rev))
            self.accR = self.e_M
            return v
        else:
            assert 0

    def __repr__(self):
        return "{}\naccL:{}, accR:{}".format(self.q,self.accL,self.accR)




# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,V,L = [int(i) for i in readline().split()]
xvw = [[int(i) for i in readline().split()] for _ in range(n)]

n += 1
xvw.append([L,0,0])

INF = 10**18
dp = [INF]*(V+1)
dp[V] = 0

D = [xvw[0][0]] + [xvw[i+1][0]-xvw[i][0] for i in range(n-1)]
for (x,v,w),d in zip(xvw,D):
    ndp = [INF]*(V+1)
    for i in range(V+1-d):
        ndp[i] = dp[i+d]
    for i in range(V,-1,-1):
        ndp[min(i+v,V)] = min(ndp[min(i+v,V)],ndp[i]+w)
    dp = ndp
    #print(dp)

x = min(dp)
if x == INF:
    print(-1)
else:
    print(x)










0