#include "jumps.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
constexpr int N = 2e5;
int h[N+9];
int l[N+9];
int r[N+9];
int dst[N+9];
int n;
constexpr int base = (1<<18);
int tree[2*base+9];
// min
void sed(int x, int a, int b, int p, int k, int val){
if (b<p || k<a)return;
if (p<=a && b<=k){
tree[x]=min(tree[x],val);
return;
}
int mid=(a+b)/2;
sed(2*x,a,mid,p,k,val);
sed(2*x+1,mid+1,b,p,k,val);
}
int query(int x){
x+=base;
int odp=1e9;
while(x){
odp=min(odp,tree[x]);
x/=2;
}
return odp;
}
bool stupido=1;
void init(int N, std::vector<int> H) {
n=N;
for (int x=0;x<n;x++){
if (h[x]!=x+1)stupido=0;
}
for (int x=0;x<n;x++)h[x]=H[x];
for (int x=0;x<=2*base+2;x++)tree[x]=1e9;
for (int x=n-1;x>=0;x--){
r[x]=query(h[x]);
sed(1,0,base-1,0,h[x],x);
}
for (int x=0;x<=2*base+2;x++)tree[x]=1e9;
for (int x=0;x<n;x++){
l[x]=-query(h[x]);
sed(1,0,base-1,0,h[x],-x);
}
/*for (int x=0;x<n;x++){
cerr << l[x] << ' ' << r[x] << '\n';
}*/
return;
}
int minimum_jumps(int A, int B, int C, int D){
if (stupido){
int odp = 1e9;
odp = min(odp,min(abs(A-C),abs(B-C)));
odp = min(odp,min(abs(A-D),abs(B-D)));
if (C<=B && B<=D)odp=0;
if (C<=A && A<=D)odp=0;
if (A<=C && D<=B)odp=0;
return odp;
}
if (A==B && C==D && 1==0){
int odp=0;
while(A!=C){
if (A<C){
A=r[A];
odp++;
}
else if (A>C){
A=l[A];
odp++;
}
if (A==-1e9 || A==1e9){
odp=-1;
break;
}
}
return odp;
}
vector<int> kol;
for (int x=0;x<n;x++)dst[x]=1e9;
for (int x=A;x<=B;x++){
dst[x]=0;
kol.push_back(x);
}
for (int y=0;y<(int)kol.size();y++){
if (C<=kol[y] && kol[y]<=D)return dst[kol[y]];
if (l[kol[y]]!=-1e9){
if (dst[l[kol[y]]]>dst[kol[y]]+1){
dst[l[kol[y]]]=dst[kol[y]]+1;
kol.push_back(l[kol[y]]);
}
}
if (r[kol[y]]!=1e9){
if (dst[r[kol[y]]]>dst[kol[y]]+1){
dst[r[kol[y]]]=dst[kol[y]]+1;
kol.push_back(r[kol[y]]);
}
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Execution timed out |
4093 ms |
7792 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
3 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4688 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
2 ms |
4696 KB |
Output is correct |
17 |
Correct |
2 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4696 KB |
Output is correct |
22 |
Correct |
2 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
2 ms |
4696 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4696 KB |
Output is correct |
27 |
Correct |
3 ms |
4696 KB |
Output is correct |
28 |
Correct |
4 ms |
4696 KB |
Output is correct |
29 |
Correct |
3 ms |
4696 KB |
Output is correct |
30 |
Correct |
4 ms |
4696 KB |
Output is correct |
31 |
Correct |
2 ms |
4724 KB |
Output is correct |
32 |
Correct |
3 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
1 ms |
4696 KB |
Output is correct |
36 |
Correct |
1 ms |
4716 KB |
Output is correct |
37 |
Correct |
1 ms |
4696 KB |
Output is correct |
38 |
Correct |
2 ms |
4696 KB |
Output is correct |
39 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
1 ms |
4696 KB |
Output is correct |
6 |
Correct |
3 ms |
4696 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
2 ms |
4696 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4688 KB |
Output is correct |
11 |
Correct |
2 ms |
4696 KB |
Output is correct |
12 |
Correct |
2 ms |
4696 KB |
Output is correct |
13 |
Correct |
2 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4696 KB |
Output is correct |
15 |
Correct |
2 ms |
4696 KB |
Output is correct |
16 |
Correct |
2 ms |
4696 KB |
Output is correct |
17 |
Correct |
2 ms |
4696 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
2 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4696 KB |
Output is correct |
22 |
Correct |
2 ms |
4696 KB |
Output is correct |
23 |
Correct |
2 ms |
4696 KB |
Output is correct |
24 |
Correct |
2 ms |
4696 KB |
Output is correct |
25 |
Correct |
2 ms |
4696 KB |
Output is correct |
26 |
Correct |
2 ms |
4696 KB |
Output is correct |
27 |
Correct |
3 ms |
4696 KB |
Output is correct |
28 |
Correct |
4 ms |
4696 KB |
Output is correct |
29 |
Correct |
3 ms |
4696 KB |
Output is correct |
30 |
Correct |
4 ms |
4696 KB |
Output is correct |
31 |
Correct |
2 ms |
4724 KB |
Output is correct |
32 |
Correct |
3 ms |
4696 KB |
Output is correct |
33 |
Correct |
2 ms |
4948 KB |
Output is correct |
34 |
Correct |
1 ms |
4696 KB |
Output is correct |
35 |
Correct |
1 ms |
4696 KB |
Output is correct |
36 |
Correct |
1 ms |
4716 KB |
Output is correct |
37 |
Correct |
1 ms |
4696 KB |
Output is correct |
38 |
Correct |
2 ms |
4696 KB |
Output is correct |
39 |
Correct |
1 ms |
4696 KB |
Output is correct |
40 |
Correct |
1 ms |
4696 KB |
Output is correct |
41 |
Correct |
2 ms |
4696 KB |
Output is correct |
42 |
Correct |
1 ms |
4696 KB |
Output is correct |
43 |
Correct |
1 ms |
4696 KB |
Output is correct |
44 |
Correct |
2 ms |
4696 KB |
Output is correct |
45 |
Correct |
2 ms |
4692 KB |
Output is correct |
46 |
Correct |
2 ms |
4696 KB |
Output is correct |
47 |
Correct |
2 ms |
4696 KB |
Output is correct |
48 |
Correct |
2 ms |
4696 KB |
Output is correct |
49 |
Correct |
2 ms |
4696 KB |
Output is correct |
50 |
Correct |
2 ms |
4696 KB |
Output is correct |
51 |
Correct |
2 ms |
4696 KB |
Output is correct |
52 |
Correct |
3 ms |
4696 KB |
Output is correct |
53 |
Correct |
2 ms |
4696 KB |
Output is correct |
54 |
Correct |
2 ms |
4696 KB |
Output is correct |
55 |
Correct |
2 ms |
4696 KB |
Output is correct |
56 |
Correct |
3 ms |
4696 KB |
Output is correct |
57 |
Correct |
1 ms |
4696 KB |
Output is correct |
58 |
Correct |
10 ms |
4696 KB |
Output is correct |
59 |
Correct |
20 ms |
4696 KB |
Output is correct |
60 |
Correct |
5 ms |
4696 KB |
Output is correct |
61 |
Correct |
22 ms |
4696 KB |
Output is correct |
62 |
Correct |
7 ms |
4696 KB |
Output is correct |
63 |
Correct |
15 ms |
4696 KB |
Output is correct |
64 |
Correct |
20 ms |
5200 KB |
Output is correct |
65 |
Correct |
17 ms |
4696 KB |
Output is correct |
66 |
Correct |
21 ms |
4696 KB |
Output is correct |
67 |
Correct |
17 ms |
4696 KB |
Output is correct |
68 |
Correct |
18 ms |
4696 KB |
Output is correct |
69 |
Correct |
22 ms |
4696 KB |
Output is correct |
70 |
Correct |
14 ms |
4696 KB |
Output is correct |
71 |
Correct |
1 ms |
4696 KB |
Output is correct |
72 |
Correct |
1 ms |
4696 KB |
Output is correct |
73 |
Correct |
2 ms |
4696 KB |
Output is correct |
74 |
Correct |
3 ms |
4696 KB |
Output is correct |
75 |
Correct |
2 ms |
4696 KB |
Output is correct |
76 |
Correct |
4 ms |
4696 KB |
Output is correct |
77 |
Correct |
2 ms |
4696 KB |
Output is correct |
78 |
Correct |
1 ms |
4696 KB |
Output is correct |
79 |
Correct |
2 ms |
4696 KB |
Output is correct |
80 |
Correct |
2 ms |
4696 KB |
Output is correct |
81 |
Correct |
2 ms |
4696 KB |
Output is correct |
82 |
Correct |
2 ms |
4696 KB |
Output is correct |
83 |
Correct |
2 ms |
4696 KB |
Output is correct |
84 |
Correct |
2 ms |
4696 KB |
Output is correct |
85 |
Correct |
2 ms |
4696 KB |
Output is correct |
86 |
Correct |
1 ms |
4696 KB |
Output is correct |
87 |
Correct |
1 ms |
4696 KB |
Output is correct |
88 |
Correct |
1 ms |
4696 KB |
Output is correct |
89 |
Correct |
1 ms |
4696 KB |
Output is correct |
90 |
Correct |
1 ms |
4696 KB |
Output is correct |
91 |
Correct |
1 ms |
4696 KB |
Output is correct |
92 |
Correct |
1 ms |
4696 KB |
Output is correct |
93 |
Correct |
1 ms |
4696 KB |
Output is correct |
94 |
Correct |
2 ms |
4696 KB |
Output is correct |
95 |
Correct |
14 ms |
4696 KB |
Output is correct |
96 |
Correct |
20 ms |
4696 KB |
Output is correct |
97 |
Correct |
18 ms |
4696 KB |
Output is correct |
98 |
Correct |
25 ms |
4696 KB |
Output is correct |
99 |
Correct |
16 ms |
4696 KB |
Output is correct |
100 |
Correct |
1 ms |
4696 KB |
Output is correct |
101 |
Correct |
1 ms |
4696 KB |
Output is correct |
102 |
Correct |
11 ms |
4696 KB |
Output is correct |
103 |
Correct |
14 ms |
4696 KB |
Output is correct |
104 |
Correct |
12 ms |
4696 KB |
Output is correct |
105 |
Correct |
14 ms |
4696 KB |
Output is correct |
106 |
Correct |
15 ms |
4696 KB |
Output is correct |
107 |
Correct |
1 ms |
4696 KB |
Output is correct |
108 |
Correct |
1 ms |
4696 KB |
Output is correct |
109 |
Correct |
2 ms |
4696 KB |
Output is correct |
110 |
Correct |
1 ms |
4696 KB |
Output is correct |
111 |
Correct |
1 ms |
4696 KB |
Output is correct |
112 |
Correct |
2 ms |
4696 KB |
Output is correct |
113 |
Correct |
1 ms |
4696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
1 ms |
4696 KB |
Output is correct |
5 |
Correct |
53 ms |
6716 KB |
Output is correct |
6 |
Correct |
66 ms |
7000 KB |
Output is correct |
7 |
Correct |
32 ms |
5720 KB |
Output is correct |
8 |
Correct |
67 ms |
8064 KB |
Output is correct |
9 |
Correct |
10 ms |
5072 KB |
Output is correct |
10 |
Correct |
66 ms |
7000 KB |
Output is correct |
11 |
Correct |
73 ms |
8060 KB |
Output is correct |
12 |
Correct |
50 ms |
7120 KB |
Output is correct |
13 |
Correct |
51 ms |
7960 KB |
Output is correct |
14 |
Correct |
62 ms |
7060 KB |
Output is correct |
15 |
Correct |
51 ms |
8000 KB |
Output is correct |
16 |
Correct |
49 ms |
8068 KB |
Output is correct |
17 |
Correct |
51 ms |
8000 KB |
Output is correct |
18 |
Correct |
1 ms |
4696 KB |
Output is correct |
19 |
Correct |
1 ms |
4696 KB |
Output is correct |
20 |
Correct |
1 ms |
4696 KB |
Output is correct |
21 |
Correct |
2 ms |
4716 KB |
Output is correct |
22 |
Correct |
1 ms |
4696 KB |
Output is correct |
23 |
Correct |
1 ms |
4696 KB |
Output is correct |
24 |
Correct |
1 ms |
4696 KB |
Output is correct |
25 |
Correct |
2 ms |
4536 KB |
Output is correct |
26 |
Correct |
1 ms |
4696 KB |
Output is correct |
27 |
Correct |
1 ms |
4696 KB |
Output is correct |
28 |
Correct |
1 ms |
4696 KB |
Output is correct |
29 |
Correct |
1 ms |
4696 KB |
Output is correct |
30 |
Correct |
2 ms |
4696 KB |
Output is correct |
31 |
Correct |
1 ms |
4744 KB |
Output is correct |
32 |
Correct |
1 ms |
4696 KB |
Output is correct |
33 |
Correct |
66 ms |
7072 KB |
Output is correct |
34 |
Correct |
66 ms |
7076 KB |
Output is correct |
35 |
Correct |
50 ms |
7916 KB |
Output is correct |
36 |
Correct |
71 ms |
7000 KB |
Output is correct |
37 |
Correct |
50 ms |
8000 KB |
Output is correct |
38 |
Correct |
62 ms |
8004 KB |
Output is correct |
39 |
Correct |
1 ms |
4696 KB |
Output is correct |
40 |
Correct |
37 ms |
6032 KB |
Output is correct |
41 |
Correct |
65 ms |
7116 KB |
Output is correct |
42 |
Correct |
49 ms |
7868 KB |
Output is correct |
43 |
Correct |
61 ms |
7000 KB |
Output is correct |
44 |
Correct |
51 ms |
8000 KB |
Output is correct |
45 |
Correct |
50 ms |
7232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
868 ms |
5560 KB |
Output is correct |
5 |
Execution timed out |
4070 ms |
7076 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
868 ms |
5560 KB |
Output is correct |
5 |
Execution timed out |
4070 ms |
7076 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4696 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Execution timed out |
4093 ms |
7792 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |