#include "jumps.h"
const int MAX_N = 200010, L = 18;
int N;
int h[MAX_N], left[MAX_N][L], right[MAX_N][L], gr[MAX_N][L];
void init(int _N, std::vector<int> _H) {
N = _N;
std::copy(_H.begin(), _H.end(), h + 1);
static int stack[MAX_N], ord[MAX_N];
int cnt = 0;
for (int i = 1; i <= N; ++i) {
while (cnt && h[i] > h[stack[cnt]])
right[stack[cnt--]][0] = i;
left[i][0] = stack[cnt];
stack[++cnt] = i;
}
for (int i = 1; i <= N; ++i) for (int j = 1; j != L; ++j)
left[i][j] = left[left[i][j - 1]][j - 1];
std::fill(right[N + 1], right[N + 1] + L, N + 1);
for (int i = N; i; --i) {
if (!right[i][0]) right[i][0] = N + 1;
for (int j = 1; j != L; ++j)
right[i][j] = right[right[i][j - 1]][j - 1];
}
for (int i = 1; i <= N; ++i) ord[h[i]] = i;
std::fill(gr[N + 1], gr[N + 1] + L, N + 1);
for (int i = N; i; --i) {
int j = ord[i];
gr[j][0] = right[j][0];
if (h[left[j][0]] > h[right[j][0]]) gr[j][0] = left[j][0];
for (int k = 1; k != L; ++k) gr[j][k] = gr[gr[j][k - 1]][k - 1];
}
}
int minimum_jumps(int A, int B, int C, int D) {
++A; ++B; ++C; ++D;
for (int i = L - 1; i >= 0; --i) if (left[D][i] >= C)
D = left[D][i];
for (int i = L - 1; i >= 0; --i) if (left[B][i] >= A && h[left[B][i]] < h[D])
B = left[B][i];
int ret = 1;
for (int i = L - 1; i >= 0; --i) if (gr[B][i] < C && h[gr[B][i]] < h[D]) {
ret += 1 << i;
B = gr[B][i];
}
for (int i = L - 1; i >= 0; --i) if (right[B][i] < C) {
ret += 1 << i;
B = right[B][i];
}
if (h[B] > h[D]) return -1;
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
195 ms |
36356 KB |
Output is correct |
4 |
Correct |
1078 ms |
45576 KB |
Output is correct |
5 |
Correct |
829 ms |
23128 KB |
Output is correct |
6 |
Correct |
1134 ms |
45620 KB |
Output is correct |
7 |
Correct |
938 ms |
31332 KB |
Output is correct |
8 |
Correct |
1101 ms |
45636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Incorrect |
3 ms |
328 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
2 ms |
328 KB |
Output is correct |
6 |
Incorrect |
3 ms |
328 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
116 ms |
36872 KB |
Output is correct |
6 |
Correct |
137 ms |
45704 KB |
Output is correct |
7 |
Correct |
63 ms |
23440 KB |
Output is correct |
8 |
Correct |
138 ms |
45636 KB |
Output is correct |
9 |
Correct |
17 ms |
7092 KB |
Output is correct |
10 |
Correct |
149 ms |
45644 KB |
Output is correct |
11 |
Correct |
86 ms |
45588 KB |
Output is correct |
12 |
Correct |
83 ms |
45588 KB |
Output is correct |
13 |
Correct |
100 ms |
45588 KB |
Output is correct |
14 |
Correct |
140 ms |
45596 KB |
Output is correct |
15 |
Incorrect |
107 ms |
46096 KB |
Output isn't correct |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
292 ms |
21016 KB |
Output is correct |
5 |
Correct |
992 ms |
45692 KB |
Output is correct |
6 |
Correct |
697 ms |
7704 KB |
Output is correct |
7 |
Correct |
1210 ms |
45688 KB |
Output is correct |
8 |
Correct |
662 ms |
15940 KB |
Output is correct |
9 |
Correct |
966 ms |
45580 KB |
Output is correct |
10 |
Correct |
1113 ms |
45632 KB |
Output is correct |
11 |
Correct |
1127 ms |
45588 KB |
Output is correct |
12 |
Correct |
1111 ms |
45588 KB |
Output is correct |
13 |
Correct |
1045 ms |
45584 KB |
Output is correct |
14 |
Correct |
851 ms |
45976 KB |
Output is correct |
15 |
Correct |
982 ms |
46400 KB |
Output is correct |
16 |
Correct |
1026 ms |
46400 KB |
Output is correct |
17 |
Correct |
0 ms |
200 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
1 ms |
200 KB |
Output is correct |
20 |
Correct |
3 ms |
328 KB |
Output is correct |
21 |
Correct |
3 ms |
328 KB |
Output is correct |
22 |
Correct |
3 ms |
328 KB |
Output is correct |
23 |
Correct |
3 ms |
328 KB |
Output is correct |
24 |
Correct |
2 ms |
328 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
456 KB |
Output is correct |
27 |
Correct |
20 ms |
712 KB |
Output is correct |
28 |
Correct |
19 ms |
712 KB |
Output is correct |
29 |
Correct |
17 ms |
712 KB |
Output is correct |
30 |
Correct |
20 ms |
712 KB |
Output is correct |
31 |
Correct |
19 ms |
712 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
33 |
Correct |
75 ms |
26476 KB |
Output is correct |
34 |
Correct |
144 ms |
45588 KB |
Output is correct |
35 |
Correct |
99 ms |
45632 KB |
Output is correct |
36 |
Correct |
132 ms |
45652 KB |
Output is correct |
37 |
Correct |
102 ms |
46048 KB |
Output is correct |
38 |
Correct |
90 ms |
46356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
292 ms |
21016 KB |
Output is correct |
5 |
Correct |
992 ms |
45692 KB |
Output is correct |
6 |
Correct |
697 ms |
7704 KB |
Output is correct |
7 |
Correct |
1210 ms |
45688 KB |
Output is correct |
8 |
Correct |
662 ms |
15940 KB |
Output is correct |
9 |
Correct |
966 ms |
45580 KB |
Output is correct |
10 |
Correct |
1113 ms |
45632 KB |
Output is correct |
11 |
Correct |
1127 ms |
45588 KB |
Output is correct |
12 |
Correct |
1111 ms |
45588 KB |
Output is correct |
13 |
Correct |
1045 ms |
45584 KB |
Output is correct |
14 |
Correct |
851 ms |
45976 KB |
Output is correct |
15 |
Correct |
982 ms |
46400 KB |
Output is correct |
16 |
Correct |
1026 ms |
46400 KB |
Output is correct |
17 |
Correct |
0 ms |
200 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
1 ms |
200 KB |
Output is correct |
20 |
Correct |
3 ms |
328 KB |
Output is correct |
21 |
Correct |
3 ms |
328 KB |
Output is correct |
22 |
Correct |
3 ms |
328 KB |
Output is correct |
23 |
Correct |
3 ms |
328 KB |
Output is correct |
24 |
Correct |
2 ms |
328 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
456 KB |
Output is correct |
27 |
Correct |
20 ms |
712 KB |
Output is correct |
28 |
Correct |
19 ms |
712 KB |
Output is correct |
29 |
Correct |
17 ms |
712 KB |
Output is correct |
30 |
Correct |
20 ms |
712 KB |
Output is correct |
31 |
Correct |
19 ms |
712 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
33 |
Correct |
75 ms |
26476 KB |
Output is correct |
34 |
Correct |
144 ms |
45588 KB |
Output is correct |
35 |
Correct |
99 ms |
45632 KB |
Output is correct |
36 |
Correct |
132 ms |
45652 KB |
Output is correct |
37 |
Correct |
102 ms |
46048 KB |
Output is correct |
38 |
Correct |
90 ms |
46356 KB |
Output is correct |
39 |
Correct |
0 ms |
200 KB |
Output is correct |
40 |
Correct |
0 ms |
200 KB |
Output is correct |
41 |
Correct |
0 ms |
200 KB |
Output is correct |
42 |
Correct |
279 ms |
21008 KB |
Output is correct |
43 |
Correct |
963 ms |
45836 KB |
Output is correct |
44 |
Correct |
694 ms |
7908 KB |
Output is correct |
45 |
Correct |
1120 ms |
45552 KB |
Output is correct |
46 |
Correct |
586 ms |
15916 KB |
Output is correct |
47 |
Correct |
1103 ms |
45632 KB |
Output is correct |
48 |
Correct |
1096 ms |
45660 KB |
Output is correct |
49 |
Correct |
1026 ms |
45632 KB |
Output is correct |
50 |
Correct |
787 ms |
45668 KB |
Output is correct |
51 |
Correct |
1094 ms |
45768 KB |
Output is correct |
52 |
Correct |
1131 ms |
46016 KB |
Output is correct |
53 |
Correct |
911 ms |
46368 KB |
Output is correct |
54 |
Correct |
1084 ms |
46352 KB |
Output is correct |
55 |
Correct |
0 ms |
200 KB |
Output is correct |
56 |
Correct |
220 ms |
45468 KB |
Output is correct |
57 |
Correct |
1198 ms |
45720 KB |
Output is correct |
58 |
Correct |
563 ms |
8244 KB |
Output is correct |
59 |
Correct |
1085 ms |
45660 KB |
Output is correct |
60 |
Correct |
469 ms |
16408 KB |
Output is correct |
61 |
Correct |
1085 ms |
45664 KB |
Output is correct |
62 |
Correct |
1115 ms |
45700 KB |
Output is correct |
63 |
Correct |
1105 ms |
45608 KB |
Output is correct |
64 |
Correct |
1025 ms |
45620 KB |
Output is correct |
65 |
Correct |
1066 ms |
45680 KB |
Output is correct |
66 |
Correct |
1158 ms |
45968 KB |
Output is correct |
67 |
Correct |
1147 ms |
46440 KB |
Output is correct |
68 |
Correct |
1026 ms |
46404 KB |
Output is correct |
69 |
Correct |
0 ms |
200 KB |
Output is correct |
70 |
Correct |
1 ms |
200 KB |
Output is correct |
71 |
Correct |
3 ms |
328 KB |
Output is correct |
72 |
Correct |
2 ms |
328 KB |
Output is correct |
73 |
Correct |
2 ms |
328 KB |
Output is correct |
74 |
Correct |
2 ms |
328 KB |
Output is correct |
75 |
Correct |
2 ms |
328 KB |
Output is correct |
76 |
Correct |
0 ms |
200 KB |
Output is correct |
77 |
Correct |
0 ms |
200 KB |
Output is correct |
78 |
Correct |
2 ms |
200 KB |
Output is correct |
79 |
Correct |
1 ms |
328 KB |
Output is correct |
80 |
Correct |
2 ms |
328 KB |
Output is correct |
81 |
Correct |
2 ms |
328 KB |
Output is correct |
82 |
Correct |
2 ms |
328 KB |
Output is correct |
83 |
Correct |
2 ms |
328 KB |
Output is correct |
84 |
Correct |
0 ms |
328 KB |
Output is correct |
85 |
Correct |
3 ms |
328 KB |
Output is correct |
86 |
Correct |
16 ms |
712 KB |
Output is correct |
87 |
Correct |
11 ms |
712 KB |
Output is correct |
88 |
Correct |
19 ms |
712 KB |
Output is correct |
89 |
Correct |
20 ms |
712 KB |
Output is correct |
90 |
Correct |
19 ms |
712 KB |
Output is correct |
91 |
Correct |
0 ms |
328 KB |
Output is correct |
92 |
Correct |
1 ms |
456 KB |
Output is correct |
93 |
Correct |
23 ms |
712 KB |
Output is correct |
94 |
Correct |
22 ms |
712 KB |
Output is correct |
95 |
Correct |
20 ms |
712 KB |
Output is correct |
96 |
Correct |
12 ms |
712 KB |
Output is correct |
97 |
Correct |
11 ms |
712 KB |
Output is correct |
98 |
Correct |
0 ms |
200 KB |
Output is correct |
99 |
Correct |
128 ms |
45588 KB |
Output is correct |
100 |
Correct |
142 ms |
45632 KB |
Output is correct |
101 |
Correct |
88 ms |
45600 KB |
Output is correct |
102 |
Correct |
123 ms |
45668 KB |
Output is correct |
103 |
Correct |
101 ms |
46100 KB |
Output is correct |
104 |
Correct |
85 ms |
46340 KB |
Output is correct |
105 |
Correct |
0 ms |
200 KB |
Output is correct |
106 |
Correct |
69 ms |
26468 KB |
Output is correct |
107 |
Correct |
150 ms |
45768 KB |
Output is correct |
108 |
Correct |
85 ms |
45600 KB |
Output is correct |
109 |
Correct |
119 ms |
45676 KB |
Output is correct |
110 |
Correct |
103 ms |
46104 KB |
Output is correct |
111 |
Correct |
100 ms |
46380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
195 ms |
36356 KB |
Output is correct |
4 |
Correct |
1078 ms |
45576 KB |
Output is correct |
5 |
Correct |
829 ms |
23128 KB |
Output is correct |
6 |
Correct |
1134 ms |
45620 KB |
Output is correct |
7 |
Correct |
938 ms |
31332 KB |
Output is correct |
8 |
Correct |
1101 ms |
45636 KB |
Output is correct |
9 |
Correct |
0 ms |
200 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
0 ms |
200 KB |
Output is correct |
12 |
Correct |
0 ms |
200 KB |
Output is correct |
13 |
Correct |
2 ms |
328 KB |
Output is correct |
14 |
Incorrect |
3 ms |
328 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |