#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v,a,b;
void init(int N, vector<int> H) {
n=N;
v=H;
a.resize(n,-1);
b.resize(n,-1);
vector<int> st;
for(int i=0;i<n;i++){
while(st.size()&&v[st.back()]<v[i]){
st.pop_back();
}
a[i]=(st.size()?st.back():-1);
st.push_back(i);
}
st.clear();
for(int i=n-1;i>=0;i--){
while(st.size()&&v[st.back()]<v[i]){
st.pop_back();
}
b[i]=(st.size()?st.back():-1);
st.push_back(i);
}
for(int i=0;i<n;i++){
if(a[i]==-1)swap(a[i],b[i]);
else if(b[i]==-1)continue;
else {
if(v[a[i]]<v[b[i]]){
swap(a[i],b[i]);
}
}
}
}
int f(int A, int C) {
int ans=0;
int now=A;
while(now!=C){
if(v[now]>v[C])return 1e9;
if(a[now]==-1&&b[now]==-1){
return 1e9;
}
if(a[now]==-1)now=b[now];
else if(b[now]==-1)now=a[now];
else{
int g1=a[now],g2=b[now];
if(v[g1]<=v[C])now=g1;
else if(v[g2]<=v[C])now=g2;
else return 1e9;
}
ans++;
}
return ans;
}
int minimum_jumps(int A, int B, int C, int D) {
int ans=1e9;
for(int i=A;i<=B;i++){
for(int j=C;j<=D;j++){
ans=min(ans,f(i,j));
}
}
if(ans==1e9)ans=-1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
4059 ms |
4508 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
500 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
33 ms |
344 KB |
Output is correct |
12 |
Correct |
24 ms |
340 KB |
Output is correct |
13 |
Correct |
11 ms |
344 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
10 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
500 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
3 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
8 |
Correct |
3 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
3 ms |
344 KB |
Output is correct |
11 |
Correct |
33 ms |
344 KB |
Output is correct |
12 |
Correct |
24 ms |
340 KB |
Output is correct |
13 |
Correct |
11 ms |
344 KB |
Output is correct |
14 |
Correct |
4 ms |
344 KB |
Output is correct |
15 |
Correct |
10 ms |
344 KB |
Output is correct |
16 |
Correct |
5 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
2 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
2 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
0 ms |
344 KB |
Output is correct |
38 |
Correct |
1 ms |
344 KB |
Output is correct |
39 |
Correct |
1 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
0 ms |
344 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
344 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
3 ms |
344 KB |
Output is correct |
46 |
Correct |
2 ms |
344 KB |
Output is correct |
47 |
Correct |
3 ms |
344 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
3 ms |
344 KB |
Output is correct |
50 |
Correct |
33 ms |
344 KB |
Output is correct |
51 |
Correct |
26 ms |
344 KB |
Output is correct |
52 |
Correct |
12 ms |
344 KB |
Output is correct |
53 |
Correct |
4 ms |
344 KB |
Output is correct |
54 |
Correct |
10 ms |
344 KB |
Output is correct |
55 |
Correct |
4 ms |
344 KB |
Output is correct |
56 |
Correct |
1 ms |
344 KB |
Output is correct |
57 |
Correct |
0 ms |
592 KB |
Output is correct |
58 |
Correct |
968 ms |
344 KB |
Output is correct |
59 |
Correct |
1775 ms |
344 KB |
Output is correct |
60 |
Correct |
81 ms |
344 KB |
Output is correct |
61 |
Correct |
1849 ms |
344 KB |
Output is correct |
62 |
Correct |
21 ms |
344 KB |
Output is correct |
63 |
Correct |
1787 ms |
344 KB |
Output is correct |
64 |
Execution timed out |
4067 ms |
344 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
2908 ms |
3600 KB |
Output is correct |
6 |
Execution timed out |
4027 ms |
4340 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
128 ms |
2412 KB |
Output is correct |
5 |
Correct |
582 ms |
4292 KB |
Output is correct |
6 |
Correct |
378 ms |
1084 KB |
Output is correct |
7 |
Correct |
584 ms |
4276 KB |
Output is correct |
8 |
Correct |
329 ms |
1624 KB |
Output is correct |
9 |
Correct |
567 ms |
4296 KB |
Output is correct |
10 |
Execution timed out |
4078 ms |
5328 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
128 ms |
2412 KB |
Output is correct |
5 |
Correct |
582 ms |
4292 KB |
Output is correct |
6 |
Correct |
378 ms |
1084 KB |
Output is correct |
7 |
Correct |
584 ms |
4276 KB |
Output is correct |
8 |
Correct |
329 ms |
1624 KB |
Output is correct |
9 |
Correct |
567 ms |
4296 KB |
Output is correct |
10 |
Execution timed out |
4078 ms |
5328 KB |
Time limit exceeded |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Execution timed out |
4059 ms |
4508 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |