#include <bits/stdc++.h>
using namespace std;
#define dbg(x) cout << #x << " " << x << endl;
const int maxN = 2e5 + 10;
int h[maxN], n, pre[maxN], nxt[maxN];
void init(int N, std::vector<int> H) {
n = N;
for(int i = 0; i < N; i++) {
h[i] = H[i];
//
nxt[i] = pre[i] = -1;
}
stack<pair<int, int>> st;
for(int i = 0; i < N; i++) {
while(!st.empty() && h[i] > st.top().first) {
nxt[st.top().second] = i;
st.pop();
}
st.push({h[i], i});
}
while(!st.empty()) st.pop();
for(int i = N - 1; i >= 0; i--) {
while(!st.empty() && h[i] > st.top().first) {
pre[st.top().second] = i;
st.pop();
}
st.push({h[i], i});
}
}
int minimum_jumps(int A, int B, int C, int D) {
queue<pair<int, int>> q;
vector<bool> vis(n + 1);
for(int i = A; i <= B; i++) {
q.push({i, 0});
vis[i] = true;
}
while(!q.empty()) {
auto u = q.front();
q.pop();
if(u.first >= C && u.first <= D) {
return u.second;
}
if(nxt[u.first] != -1 && !vis[nxt[u.first]]) {
vis[nxt[u.first]] = true;
q.push({nxt[u.first], u.second + 1});
}
if(pre[u.first] != -1 && !vis[pre[u.first]]) {
vis[pre[u.first]] = true;
q.push({pre[u.first], u.second + 1});
}
}
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Execution timed out |
4042 ms |
4632 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
3 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
2 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
2 ms |
208 KB |
Output is correct |
28 |
Correct |
2 ms |
208 KB |
Output is correct |
29 |
Correct |
2 ms |
208 KB |
Output is correct |
30 |
Correct |
2 ms |
208 KB |
Output is correct |
31 |
Correct |
2 ms |
208 KB |
Output is correct |
32 |
Correct |
2 ms |
208 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
1 ms |
208 KB |
Output is correct |
37 |
Correct |
1 ms |
208 KB |
Output is correct |
38 |
Correct |
0 ms |
208 KB |
Output is correct |
39 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
3 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
4 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
2 ms |
208 KB |
Output is correct |
11 |
Correct |
3 ms |
208 KB |
Output is correct |
12 |
Correct |
3 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
3 ms |
300 KB |
Output is correct |
15 |
Correct |
2 ms |
304 KB |
Output is correct |
16 |
Correct |
2 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
1 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
3 ms |
208 KB |
Output is correct |
21 |
Correct |
3 ms |
208 KB |
Output is correct |
22 |
Correct |
3 ms |
208 KB |
Output is correct |
23 |
Correct |
3 ms |
208 KB |
Output is correct |
24 |
Correct |
2 ms |
208 KB |
Output is correct |
25 |
Correct |
1 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
208 KB |
Output is correct |
27 |
Correct |
2 ms |
208 KB |
Output is correct |
28 |
Correct |
2 ms |
208 KB |
Output is correct |
29 |
Correct |
2 ms |
208 KB |
Output is correct |
30 |
Correct |
2 ms |
208 KB |
Output is correct |
31 |
Correct |
2 ms |
208 KB |
Output is correct |
32 |
Correct |
2 ms |
208 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
1 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
1 ms |
208 KB |
Output is correct |
37 |
Correct |
1 ms |
208 KB |
Output is correct |
38 |
Correct |
0 ms |
208 KB |
Output is correct |
39 |
Correct |
1 ms |
208 KB |
Output is correct |
40 |
Correct |
0 ms |
208 KB |
Output is correct |
41 |
Correct |
0 ms |
208 KB |
Output is correct |
42 |
Correct |
0 ms |
208 KB |
Output is correct |
43 |
Correct |
0 ms |
208 KB |
Output is correct |
44 |
Correct |
2 ms |
208 KB |
Output is correct |
45 |
Correct |
2 ms |
208 KB |
Output is correct |
46 |
Correct |
2 ms |
208 KB |
Output is correct |
47 |
Correct |
3 ms |
208 KB |
Output is correct |
48 |
Correct |
2 ms |
320 KB |
Output is correct |
49 |
Correct |
2 ms |
208 KB |
Output is correct |
50 |
Correct |
3 ms |
208 KB |
Output is correct |
51 |
Correct |
3 ms |
208 KB |
Output is correct |
52 |
Correct |
3 ms |
208 KB |
Output is correct |
53 |
Correct |
3 ms |
208 KB |
Output is correct |
54 |
Correct |
2 ms |
208 KB |
Output is correct |
55 |
Correct |
2 ms |
208 KB |
Output is correct |
56 |
Correct |
3 ms |
208 KB |
Output is correct |
57 |
Correct |
0 ms |
208 KB |
Output is correct |
58 |
Correct |
26 ms |
336 KB |
Output is correct |
59 |
Correct |
37 ms |
336 KB |
Output is correct |
60 |
Correct |
9 ms |
332 KB |
Output is correct |
61 |
Correct |
32 ms |
336 KB |
Output is correct |
62 |
Correct |
13 ms |
208 KB |
Output is correct |
63 |
Correct |
30 ms |
336 KB |
Output is correct |
64 |
Correct |
50 ms |
336 KB |
Output is correct |
65 |
Correct |
49 ms |
336 KB |
Output is correct |
66 |
Correct |
44 ms |
336 KB |
Output is correct |
67 |
Correct |
31 ms |
336 KB |
Output is correct |
68 |
Correct |
46 ms |
336 KB |
Output is correct |
69 |
Correct |
39 ms |
336 KB |
Output is correct |
70 |
Correct |
28 ms |
336 KB |
Output is correct |
71 |
Correct |
0 ms |
208 KB |
Output is correct |
72 |
Correct |
1 ms |
208 KB |
Output is correct |
73 |
Correct |
2 ms |
208 KB |
Output is correct |
74 |
Correct |
3 ms |
208 KB |
Output is correct |
75 |
Correct |
3 ms |
208 KB |
Output is correct |
76 |
Correct |
2 ms |
208 KB |
Output is correct |
77 |
Correct |
3 ms |
208 KB |
Output is correct |
78 |
Correct |
0 ms |
208 KB |
Output is correct |
79 |
Correct |
1 ms |
208 KB |
Output is correct |
80 |
Correct |
1 ms |
208 KB |
Output is correct |
81 |
Correct |
3 ms |
208 KB |
Output is correct |
82 |
Correct |
2 ms |
300 KB |
Output is correct |
83 |
Correct |
3 ms |
208 KB |
Output is correct |
84 |
Correct |
3 ms |
208 KB |
Output is correct |
85 |
Correct |
3 ms |
208 KB |
Output is correct |
86 |
Correct |
0 ms |
208 KB |
Output is correct |
87 |
Correct |
1 ms |
208 KB |
Output is correct |
88 |
Correct |
0 ms |
208 KB |
Output is correct |
89 |
Correct |
1 ms |
208 KB |
Output is correct |
90 |
Correct |
1 ms |
300 KB |
Output is correct |
91 |
Correct |
1 ms |
208 KB |
Output is correct |
92 |
Correct |
0 ms |
208 KB |
Output is correct |
93 |
Correct |
1 ms |
208 KB |
Output is correct |
94 |
Correct |
4 ms |
208 KB |
Output is correct |
95 |
Correct |
32 ms |
336 KB |
Output is correct |
96 |
Correct |
45 ms |
344 KB |
Output is correct |
97 |
Correct |
37 ms |
336 KB |
Output is correct |
98 |
Correct |
46 ms |
300 KB |
Output is correct |
99 |
Correct |
45 ms |
300 KB |
Output is correct |
100 |
Correct |
1 ms |
208 KB |
Output is correct |
101 |
Correct |
1 ms |
208 KB |
Output is correct |
102 |
Correct |
17 ms |
304 KB |
Output is correct |
103 |
Correct |
34 ms |
336 KB |
Output is correct |
104 |
Correct |
16 ms |
336 KB |
Output is correct |
105 |
Correct |
36 ms |
336 KB |
Output is correct |
106 |
Correct |
37 ms |
336 KB |
Output is correct |
107 |
Correct |
0 ms |
208 KB |
Output is correct |
108 |
Correct |
1 ms |
208 KB |
Output is correct |
109 |
Correct |
1 ms |
336 KB |
Output is correct |
110 |
Correct |
1 ms |
336 KB |
Output is correct |
111 |
Correct |
1 ms |
336 KB |
Output is correct |
112 |
Correct |
1 ms |
336 KB |
Output is correct |
113 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
208 KB |
Output is correct |
5 |
Correct |
24 ms |
3492 KB |
Output is correct |
6 |
Correct |
29 ms |
4208 KB |
Output is correct |
7 |
Correct |
14 ms |
2228 KB |
Output is correct |
8 |
Correct |
31 ms |
4960 KB |
Output is correct |
9 |
Correct |
4 ms |
936 KB |
Output is correct |
10 |
Correct |
29 ms |
4168 KB |
Output is correct |
11 |
Correct |
44 ms |
5812 KB |
Output is correct |
12 |
Correct |
31 ms |
5400 KB |
Output is correct |
13 |
Correct |
44 ms |
5364 KB |
Output is correct |
14 |
Correct |
29 ms |
4168 KB |
Output is correct |
15 |
Correct |
33 ms |
5028 KB |
Output is correct |
16 |
Correct |
30 ms |
5648 KB |
Output is correct |
17 |
Correct |
32 ms |
5684 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
0 ms |
208 KB |
Output is correct |
21 |
Correct |
1 ms |
208 KB |
Output is correct |
22 |
Correct |
1 ms |
208 KB |
Output is correct |
23 |
Correct |
1 ms |
208 KB |
Output is correct |
24 |
Correct |
1 ms |
208 KB |
Output is correct |
25 |
Correct |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
356 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |
33 |
Correct |
43 ms |
4116 KB |
Output is correct |
34 |
Correct |
31 ms |
4156 KB |
Output is correct |
35 |
Correct |
37 ms |
5428 KB |
Output is correct |
36 |
Correct |
28 ms |
4128 KB |
Output is correct |
37 |
Correct |
29 ms |
4920 KB |
Output is correct |
38 |
Correct |
29 ms |
5796 KB |
Output is correct |
39 |
Correct |
1 ms |
208 KB |
Output is correct |
40 |
Correct |
21 ms |
2560 KB |
Output is correct |
41 |
Correct |
28 ms |
4136 KB |
Output is correct |
42 |
Correct |
26 ms |
5524 KB |
Output is correct |
43 |
Correct |
29 ms |
4216 KB |
Output is correct |
44 |
Correct |
29 ms |
4936 KB |
Output is correct |
45 |
Correct |
28 ms |
5800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
256 ms |
2072 KB |
Output is correct |
5 |
Correct |
913 ms |
4120 KB |
Output is correct |
6 |
Correct |
567 ms |
940 KB |
Output is correct |
7 |
Correct |
1018 ms |
4148 KB |
Output is correct |
8 |
Correct |
582 ms |
1576 KB |
Output is correct |
9 |
Correct |
971 ms |
4168 KB |
Output is correct |
10 |
Execution timed out |
4006 ms |
5836 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
256 ms |
2072 KB |
Output is correct |
5 |
Correct |
913 ms |
4120 KB |
Output is correct |
6 |
Correct |
567 ms |
940 KB |
Output is correct |
7 |
Correct |
1018 ms |
4148 KB |
Output is correct |
8 |
Correct |
582 ms |
1576 KB |
Output is correct |
9 |
Correct |
971 ms |
4168 KB |
Output is correct |
10 |
Execution timed out |
4006 ms |
5836 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Execution timed out |
4042 ms |
4632 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |