結果

問題 No.1037 exhausted
ユーザー convexineqconvexineq
提出日時 2020-04-24 22:24:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,991 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 82,388 KB
実行使用メモリ 77,492 KB
最終ジャッジ日時 2024-04-23 03:34:49
合計ジャッジ時間 2,178 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,604 KB
testcase_01 AC 36 ms
54,464 KB
testcase_02 AC 36 ms
55,308 KB
testcase_03 AC 38 ms
54,804 KB
testcase_04 WA -
testcase_05 AC 36 ms
54,420 KB
testcase_06 AC 36 ms
55,456 KB
testcase_07 AC 37 ms
54,292 KB
testcase_08 AC 37 ms
55,316 KB
testcase_09 AC 37 ms
55,264 KB
testcase_10 AC 38 ms
56,044 KB
testcase_11 WA -
testcase_12 AC 86 ms
77,136 KB
testcase_13 AC 89 ms
77,020 KB
testcase_14 WA -
testcase_15 AC 87 ms
77,144 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 82 ms
76,796 KB
testcase_19 AC 86 ms
77,040 KB
testcase_20 AC 78 ms
76,744 KB
testcase_21 AC 76 ms
76,900 KB
testcase_22 AC 78 ms
76,792 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)] + [L - xvw[-2][0]]
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,v-1,-1):
        ndp[i] = min(ndp[i],ndp[i-v]+w)
    dp = ndp
    #print(dp)

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










0