#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define rep1(i, a, b) for (int i = (int)a; i >= (int)b; --i)
#define mp make_pair
constexpr int kMaxLogN = 20;
int N;
vector<int> H;
vector<vector<int>> L, R;
vector<vector<int>> higher;
void init(int _N, std::vector<int> _H) {
N = _N;
H = _H;
H.insert(H.begin(), INT_MAX);
H.insert(H.end(), INT_MAX);
N += 2;
L = R = higher = vector<vector<int>>(kMaxLogN, vector<int>(N));
stack<int> decreasing_height;
for (int i = 0; i < N; ++i) {
while (!decreasing_height.empty() && H[decreasing_height.top()] <= H[i]) {
decreasing_height.pop();
}
L[0][i] = decreasing_height.empty() ? i : decreasing_height.top();
decreasing_height.push(i);
}
while (!decreasing_height.empty()) {
decreasing_height.pop();
}
for (int i = N - 1; i >= 0; --i) {
while (!decreasing_height.empty() && H[decreasing_height.top()] <= H[i]) {
decreasing_height.pop();
}
R[0][i] = decreasing_height.empty() ? i : decreasing_height.top();
decreasing_height.push(i);
}
for (int i = 0; i < N; ++i) {
higher[0][i] = H[L[0][i]] > H[R[0][i]] ? L[0][i] : R[0][i];
}
for (int j = 1; j < kMaxLogN; ++j) {
for (int i = 0; i < N; ++i) {
L[j][i] = L[j - 1][L[j - 1][i]];
R[j][i] = R[j - 1][R[j - 1][i]];
higher[j][i] = higher[j - 1][higher[j - 1][i]];
}
}
}
int minimum_jumps(int s, int e) {
int jumps = 0;
for (int j = kMaxLogN - 1; j >= 0; --j) {
if (H[higher[j][s]] <= H[e]) {
s = higher[j][s];
jumps |= (1 << j);
}
}
if (s != e) {
for (int j = kMaxLogN - 1; j >= 0; --j) {
if (H[R[j][s]] <= H[e]) {
s = R[j][s];
jumps += (1 << j);
}
}
}
return s == e ? jumps : -1;
}
int minimum_jumps(int A, int B, int C, int D) {
++A; ++B; ++C; ++D;
return minimum_jumps(B, C);
}
# |
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 |
141 ms |
40104 KB |
Output is correct |
4 |
Correct |
1177 ms |
50440 KB |
Output is correct |
5 |
Correct |
1074 ms |
25524 KB |
Output is correct |
6 |
Correct |
1078 ms |
50304 KB |
Output is correct |
7 |
Correct |
1000 ms |
34472 KB |
Output is correct |
8 |
Correct |
1182 ms |
50308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
270 ms |
23124 KB |
Output is correct |
5 |
Correct |
905 ms |
50428 KB |
Output is correct |
6 |
Correct |
742 ms |
8516 KB |
Output is correct |
7 |
Correct |
1297 ms |
50324 KB |
Output is correct |
8 |
Correct |
651 ms |
17456 KB |
Output is correct |
9 |
Correct |
1297 ms |
50352 KB |
Output is correct |
10 |
Correct |
1377 ms |
50424 KB |
Output is correct |
11 |
Correct |
1145 ms |
50308 KB |
Output is correct |
12 |
Correct |
1179 ms |
50352 KB |
Output is correct |
13 |
Correct |
1032 ms |
50284 KB |
Output is correct |
14 |
Correct |
1145 ms |
50308 KB |
Output is correct |
15 |
Correct |
1205 ms |
50520 KB |
Output is correct |
16 |
Correct |
1016 ms |
50432 KB |
Output is correct |
17 |
Correct |
0 ms |
200 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
2 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 |
2 ms |
328 KB |
Output is correct |
23 |
Correct |
2 ms |
328 KB |
Output is correct |
24 |
Correct |
3 ms |
328 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
22 ms |
832 KB |
Output is correct |
28 |
Correct |
26 ms |
712 KB |
Output is correct |
29 |
Correct |
23 ms |
832 KB |
Output is correct |
30 |
Correct |
19 ms |
712 KB |
Output is correct |
31 |
Correct |
24 ms |
712 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
33 |
Correct |
44 ms |
29176 KB |
Output is correct |
34 |
Correct |
59 ms |
50304 KB |
Output is correct |
35 |
Correct |
57 ms |
50308 KB |
Output is correct |
36 |
Correct |
58 ms |
50412 KB |
Output is correct |
37 |
Correct |
73 ms |
50324 KB |
Output is correct |
38 |
Correct |
74 ms |
50320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
270 ms |
23124 KB |
Output is correct |
5 |
Correct |
905 ms |
50428 KB |
Output is correct |
6 |
Correct |
742 ms |
8516 KB |
Output is correct |
7 |
Correct |
1297 ms |
50324 KB |
Output is correct |
8 |
Correct |
651 ms |
17456 KB |
Output is correct |
9 |
Correct |
1297 ms |
50352 KB |
Output is correct |
10 |
Correct |
1377 ms |
50424 KB |
Output is correct |
11 |
Correct |
1145 ms |
50308 KB |
Output is correct |
12 |
Correct |
1179 ms |
50352 KB |
Output is correct |
13 |
Correct |
1032 ms |
50284 KB |
Output is correct |
14 |
Correct |
1145 ms |
50308 KB |
Output is correct |
15 |
Correct |
1205 ms |
50520 KB |
Output is correct |
16 |
Correct |
1016 ms |
50432 KB |
Output is correct |
17 |
Correct |
0 ms |
200 KB |
Output is correct |
18 |
Correct |
0 ms |
200 KB |
Output is correct |
19 |
Correct |
2 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 |
2 ms |
328 KB |
Output is correct |
23 |
Correct |
2 ms |
328 KB |
Output is correct |
24 |
Correct |
3 ms |
328 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
2 ms |
456 KB |
Output is correct |
27 |
Correct |
22 ms |
832 KB |
Output is correct |
28 |
Correct |
26 ms |
712 KB |
Output is correct |
29 |
Correct |
23 ms |
832 KB |
Output is correct |
30 |
Correct |
19 ms |
712 KB |
Output is correct |
31 |
Correct |
24 ms |
712 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
33 |
Correct |
44 ms |
29176 KB |
Output is correct |
34 |
Correct |
59 ms |
50304 KB |
Output is correct |
35 |
Correct |
57 ms |
50308 KB |
Output is correct |
36 |
Correct |
58 ms |
50412 KB |
Output is correct |
37 |
Correct |
73 ms |
50324 KB |
Output is correct |
38 |
Correct |
74 ms |
50320 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 |
263 ms |
23208 KB |
Output is correct |
43 |
Correct |
1202 ms |
50308 KB |
Output is correct |
44 |
Correct |
735 ms |
8516 KB |
Output is correct |
45 |
Correct |
1038 ms |
50292 KB |
Output is correct |
46 |
Correct |
355 ms |
17444 KB |
Output is correct |
47 |
Correct |
966 ms |
50392 KB |
Output is correct |
48 |
Correct |
1159 ms |
50424 KB |
Output is correct |
49 |
Correct |
1204 ms |
50312 KB |
Output is correct |
50 |
Correct |
1179 ms |
50352 KB |
Output is correct |
51 |
Correct |
1038 ms |
50352 KB |
Output is correct |
52 |
Correct |
1184 ms |
50312 KB |
Output is correct |
53 |
Correct |
1109 ms |
50336 KB |
Output is correct |
54 |
Correct |
1049 ms |
50352 KB |
Output is correct |
55 |
Correct |
0 ms |
200 KB |
Output is correct |
56 |
Incorrect |
117 ms |
50172 KB |
Output isn't correct |
57 |
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 |
141 ms |
40104 KB |
Output is correct |
4 |
Correct |
1177 ms |
50440 KB |
Output is correct |
5 |
Correct |
1074 ms |
25524 KB |
Output is correct |
6 |
Correct |
1078 ms |
50304 KB |
Output is correct |
7 |
Correct |
1000 ms |
34472 KB |
Output is correct |
8 |
Correct |
1182 ms |
50308 KB |
Output is correct |
9 |
Incorrect |
1 ms |
200 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |