제출 #113011

#제출 시각아이디문제언어결과실행 시간메모리
113011jh05013Pinball (JOI14_pinball)Pypy 2
51 / 100
1081 ms85712 KiB
input = __import__('sys').stdin.readline MIS = lambda: map(int,input().split()) range = xrange INF = 10**18 class SegTree: def __init__(_, n): _.n = 1 while _.n < n: _.n<<= 1 _.arr = [INF]*(_.n*2) def update(_, i, val): i+= _.n if _.arr[i] < val: return _.arr[i] = val while i > 1: i//=2; _.arr[i] = min(_.arr[2*i], _.arr[2*i+1]) def query(_, l, r): a = INF; l+= _.n; r+= _.n+1 while l < r: if l&1: a = min(a, _.arr[l]); l+= 1 if r&1: r-= 1; a = min(a, _.arr[r]) l>>=1; r>>=1 return a n, m = MIS() plat = [tuple(MIS()) for i in range(n)] C = {1, m} for l, r, c, cost in plat: C|= {l,r,c} C = dict(zip(sorted(C), range(len(C)))) plat = [(C[l], C[r], C[c], cost) for l, r, c, cost in plat] # dpl[i] = "#1 falls to i-th platform" ST = SegTree(len(C)) dpl = [] for i in range(n): l, r, c, cost = plat[i] if l == 0: dpl.append(cost) ST.update(c, cost) continue val = cost + ST.query(l, r) dpl.append(val) ST.update(c, val) # dpu[i] = "#m falls to i-th platform" ST = SegTree(len(C)) dpr = [] for i in range(n): l, r, c, cost = plat[i] if r == len(C)-1: dpr.append(cost) ST.update(c, cost) continue val = cost + ST.query(l, r) dpr.append(val) ST.update(c, val) ans = min(dpl[i]+dpr[i]-plat[i][3] for i in range(n)) print(ans if ans < INF else -1)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...