# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
113011 |
2019-05-23T04:08:04 Z |
jh05013 |
Pinball (JOI14_pinball) |
PyPy |
|
1000 ms |
85712 KB |
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 time |
Memory |
Grader output |
1 |
Correct |
27 ms |
11240 KB |
Output is correct |
2 |
Correct |
26 ms |
11240 KB |
Output is correct |
3 |
Correct |
28 ms |
11240 KB |
Output is correct |
4 |
Correct |
27 ms |
11324 KB |
Output is correct |
5 |
Correct |
27 ms |
11240 KB |
Output is correct |
6 |
Correct |
28 ms |
11208 KB |
Output is correct |
7 |
Correct |
27 ms |
11248 KB |
Output is correct |
8 |
Correct |
28 ms |
11248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
11240 KB |
Output is correct |
2 |
Correct |
26 ms |
11240 KB |
Output is correct |
3 |
Correct |
28 ms |
11240 KB |
Output is correct |
4 |
Correct |
27 ms |
11324 KB |
Output is correct |
5 |
Correct |
27 ms |
11240 KB |
Output is correct |
6 |
Correct |
28 ms |
11208 KB |
Output is correct |
7 |
Correct |
27 ms |
11248 KB |
Output is correct |
8 |
Correct |
28 ms |
11248 KB |
Output is correct |
9 |
Correct |
41 ms |
14568 KB |
Output is correct |
10 |
Correct |
39 ms |
11748 KB |
Output is correct |
11 |
Correct |
41 ms |
11880 KB |
Output is correct |
12 |
Correct |
39 ms |
11752 KB |
Output is correct |
13 |
Correct |
37 ms |
11752 KB |
Output is correct |
14 |
Correct |
39 ms |
11624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
11240 KB |
Output is correct |
2 |
Correct |
26 ms |
11240 KB |
Output is correct |
3 |
Correct |
28 ms |
11240 KB |
Output is correct |
4 |
Correct |
27 ms |
11324 KB |
Output is correct |
5 |
Correct |
27 ms |
11240 KB |
Output is correct |
6 |
Correct |
28 ms |
11208 KB |
Output is correct |
7 |
Correct |
27 ms |
11248 KB |
Output is correct |
8 |
Correct |
28 ms |
11248 KB |
Output is correct |
9 |
Correct |
41 ms |
14568 KB |
Output is correct |
10 |
Correct |
39 ms |
11748 KB |
Output is correct |
11 |
Correct |
41 ms |
11880 KB |
Output is correct |
12 |
Correct |
39 ms |
11752 KB |
Output is correct |
13 |
Correct |
37 ms |
11752 KB |
Output is correct |
14 |
Correct |
39 ms |
11624 KB |
Output is correct |
15 |
Correct |
30 ms |
11376 KB |
Output is correct |
16 |
Correct |
48 ms |
12100 KB |
Output is correct |
17 |
Correct |
104 ms |
13244 KB |
Output is correct |
18 |
Correct |
60 ms |
12132 KB |
Output is correct |
19 |
Correct |
84 ms |
12740 KB |
Output is correct |
20 |
Correct |
102 ms |
13180 KB |
Output is correct |
21 |
Correct |
50 ms |
12132 KB |
Output is correct |
22 |
Correct |
88 ms |
12772 KB |
Output is correct |
23 |
Correct |
96 ms |
12524 KB |
Output is correct |
24 |
Correct |
75 ms |
12516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
11240 KB |
Output is correct |
2 |
Correct |
26 ms |
11240 KB |
Output is correct |
3 |
Correct |
28 ms |
11240 KB |
Output is correct |
4 |
Correct |
27 ms |
11324 KB |
Output is correct |
5 |
Correct |
27 ms |
11240 KB |
Output is correct |
6 |
Correct |
28 ms |
11208 KB |
Output is correct |
7 |
Correct |
27 ms |
11248 KB |
Output is correct |
8 |
Correct |
28 ms |
11248 KB |
Output is correct |
9 |
Correct |
41 ms |
14568 KB |
Output is correct |
10 |
Correct |
39 ms |
11748 KB |
Output is correct |
11 |
Correct |
41 ms |
11880 KB |
Output is correct |
12 |
Correct |
39 ms |
11752 KB |
Output is correct |
13 |
Correct |
37 ms |
11752 KB |
Output is correct |
14 |
Correct |
39 ms |
11624 KB |
Output is correct |
15 |
Correct |
30 ms |
11376 KB |
Output is correct |
16 |
Correct |
48 ms |
12100 KB |
Output is correct |
17 |
Correct |
104 ms |
13244 KB |
Output is correct |
18 |
Correct |
60 ms |
12132 KB |
Output is correct |
19 |
Correct |
84 ms |
12740 KB |
Output is correct |
20 |
Correct |
102 ms |
13180 KB |
Output is correct |
21 |
Correct |
50 ms |
12132 KB |
Output is correct |
22 |
Correct |
88 ms |
12772 KB |
Output is correct |
23 |
Correct |
96 ms |
12524 KB |
Output is correct |
24 |
Correct |
75 ms |
12516 KB |
Output is correct |
25 |
Correct |
337 ms |
24508 KB |
Output is correct |
26 |
Correct |
451 ms |
35856 KB |
Output is correct |
27 |
Correct |
713 ms |
60564 KB |
Output is correct |
28 |
Correct |
418 ms |
53100 KB |
Output is correct |
29 |
Correct |
622 ms |
51476 KB |
Output is correct |
30 |
Correct |
750 ms |
59228 KB |
Output is correct |
31 |
Execution timed out |
1081 ms |
85712 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |