#include "jumps.h"
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b); i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define mp make_pair
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second
#define out(x) cout<<x<<'\n';
#define in(x) cin>>x;
#define inarr(a,x,y) for(int i=x;i<y;i++){cin>>a[i];}
#define incor(a,x,y) for(int i=x;i<y;i++){cin>>a[i].f>>a[i].s;}
const int mod = 1e9 + 7;
const int maxn = 2e3 + 5;
int h[maxn], lft[maxn], rgt[maxn], dp[maxn], n;
int ok = 1;
void init(int N, std::vector<int> H)
{
for (int i = 0; i < N; i++) {
if (H[i] != i + 1) ok = 0;
}
if (ok == 1) return;
n = N;
FOR(i, 0, n)
h[i] = H[i];
FOR(i, 0, n)
{
lft[i] = rgt[i] = i;
for (int j = i - 1; j >= 0; --j)
if (h[j] > h[i])
{
lft[i] = j;
break;
}
for (int j = i + 1; j < n; ++j)
if (h[j] > h[i])
{
rgt[i] = j;
break;
}
}
}
int minimum_jumps(int a, int b, int c, int d)
{
if (ok == 1) {
if (c <= b) return 0;
else return c - b;
}
FOR(i, 0, n)
dp[i] = mod;
queue<int> q;
FOR(i, a, b + 1)
{
dp[i] = 0;
q.push(i);
}
while (sz(q))
{
int u = q.front(); q.pop();
if (u >= c && u <= d) return dp[u];
if (dp[lft[u]] == mod)
{
dp[lft[u]] = dp[u] + 1;
q.push(lft[u]);
}
if (dp[rgt[u]] == mod)
{
dp[rgt[u]] = dp[u] + 1;
q.push(rgt[u]);
}
}
return -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
107 ms |
1424 KB |
Output is correct |
4 |
Correct |
715 ms |
1840 KB |
Output is correct |
5 |
Correct |
736 ms |
976 KB |
Output is correct |
6 |
Correct |
918 ms |
1764 KB |
Output is correct |
7 |
Correct |
443 ms |
1352 KB |
Output is correct |
8 |
Correct |
793 ms |
1856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 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 |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
208 KB |
Output is correct |
27 |
Correct |
1 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 |
4 ms |
208 KB |
Output is correct |
32 |
Correct |
3 ms |
208 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
0 ms |
208 KB |
Output is correct |
35 |
Correct |
0 ms |
208 KB |
Output is correct |
36 |
Correct |
0 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 |
0 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
2 ms |
208 KB |
Output is correct |
6 |
Correct |
2 ms |
208 KB |
Output is correct |
7 |
Correct |
2 ms |
208 KB |
Output is correct |
8 |
Correct |
3 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
3 ms |
208 KB |
Output is correct |
11 |
Correct |
2 ms |
208 KB |
Output is correct |
12 |
Correct |
2 ms |
208 KB |
Output is correct |
13 |
Correct |
3 ms |
208 KB |
Output is correct |
14 |
Correct |
3 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
4 ms |
208 KB |
Output is correct |
17 |
Correct |
2 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 KB |
Output is correct |
19 |
Correct |
1 ms |
208 KB |
Output is correct |
20 |
Correct |
2 ms |
208 KB |
Output is correct |
21 |
Correct |
2 ms |
208 KB |
Output is correct |
22 |
Correct |
2 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 |
0 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
208 KB |
Output is correct |
27 |
Correct |
1 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 |
4 ms |
208 KB |
Output is correct |
32 |
Correct |
3 ms |
208 KB |
Output is correct |
33 |
Correct |
0 ms |
208 KB |
Output is correct |
34 |
Correct |
0 ms |
208 KB |
Output is correct |
35 |
Correct |
0 ms |
208 KB |
Output is correct |
36 |
Correct |
0 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 |
0 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 |
2 ms |
208 KB |
Output is correct |
48 |
Correct |
1 ms |
208 KB |
Output is correct |
49 |
Correct |
2 ms |
208 KB |
Output is correct |
50 |
Correct |
1 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 |
3 ms |
208 KB |
Output is correct |
55 |
Correct |
2 ms |
208 KB |
Output is correct |
56 |
Correct |
2 ms |
208 KB |
Output is correct |
57 |
Correct |
0 ms |
208 KB |
Output is correct |
58 |
Correct |
18 ms |
336 KB |
Output is correct |
59 |
Correct |
25 ms |
336 KB |
Output is correct |
60 |
Correct |
6 ms |
336 KB |
Output is correct |
61 |
Correct |
29 ms |
336 KB |
Output is correct |
62 |
Correct |
11 ms |
208 KB |
Output is correct |
63 |
Correct |
25 ms |
336 KB |
Output is correct |
64 |
Correct |
15 ms |
208 KB |
Output is correct |
65 |
Correct |
33 ms |
336 KB |
Output is correct |
66 |
Correct |
35 ms |
336 KB |
Output is correct |
67 |
Correct |
26 ms |
336 KB |
Output is correct |
68 |
Correct |
37 ms |
336 KB |
Output is correct |
69 |
Correct |
29 ms |
336 KB |
Output is correct |
70 |
Correct |
25 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 |
3 ms |
208 KB |
Output is correct |
74 |
Correct |
2 ms |
208 KB |
Output is correct |
75 |
Correct |
3 ms |
208 KB |
Output is correct |
76 |
Correct |
3 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 |
0 ms |
208 KB |
Output is correct |
80 |
Correct |
1 ms |
208 KB |
Output is correct |
81 |
Correct |
1 ms |
208 KB |
Output is correct |
82 |
Correct |
2 ms |
208 KB |
Output is correct |
83 |
Correct |
2 ms |
208 KB |
Output is correct |
84 |
Correct |
2 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 |
0 ms |
208 KB |
Output is correct |
88 |
Correct |
1 ms |
208 KB |
Output is correct |
89 |
Correct |
0 ms |
284 KB |
Output is correct |
90 |
Correct |
0 ms |
208 KB |
Output is correct |
91 |
Correct |
0 ms |
208 KB |
Output is correct |
92 |
Correct |
1 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 |
28 ms |
336 KB |
Output is correct |
96 |
Correct |
31 ms |
336 KB |
Output is correct |
97 |
Correct |
26 ms |
336 KB |
Output is correct |
98 |
Correct |
39 ms |
336 KB |
Output is correct |
99 |
Correct |
35 ms |
336 KB |
Output is correct |
100 |
Correct |
0 ms |
208 KB |
Output is correct |
101 |
Correct |
1 ms |
208 KB |
Output is correct |
102 |
Correct |
17 ms |
336 KB |
Output is correct |
103 |
Correct |
25 ms |
336 KB |
Output is correct |
104 |
Correct |
19 ms |
336 KB |
Output is correct |
105 |
Correct |
27 ms |
336 KB |
Output is correct |
106 |
Correct |
25 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 |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
208 KB |
Output is correct |
5 |
Runtime error |
17 ms |
2976 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
Runtime error |
15 ms |
1872 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
Runtime error |
15 ms |
1872 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
107 ms |
1424 KB |
Output is correct |
4 |
Correct |
715 ms |
1840 KB |
Output is correct |
5 |
Correct |
736 ms |
976 KB |
Output is correct |
6 |
Correct |
918 ms |
1764 KB |
Output is correct |
7 |
Correct |
443 ms |
1352 KB |
Output is correct |
8 |
Correct |
793 ms |
1856 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
0 ms |
208 KB |
Output is correct |
12 |
Correct |
0 ms |
208 KB |
Output is correct |
13 |
Correct |
2 ms |
208 KB |
Output is correct |
14 |
Correct |
2 ms |
208 KB |
Output is correct |
15 |
Correct |
2 ms |
208 KB |
Output is correct |
16 |
Correct |
3 ms |
208 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
3 ms |
208 KB |
Output is correct |
19 |
Correct |
2 ms |
208 KB |
Output is correct |
20 |
Correct |
2 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 |
2 ms |
208 KB |
Output is correct |
24 |
Correct |
4 ms |
208 KB |
Output is correct |
25 |
Correct |
2 ms |
208 KB |
Output is correct |
26 |
Correct |
0 ms |
208 KB |
Output is correct |
27 |
Correct |
1 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 |
3 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 |
0 ms |
208 KB |
Output is correct |
35 |
Correct |
1 ms |
208 KB |
Output is correct |
36 |
Correct |
2 ms |
208 KB |
Output is correct |
37 |
Correct |
2 ms |
208 KB |
Output is correct |
38 |
Correct |
2 ms |
208 KB |
Output is correct |
39 |
Correct |
4 ms |
208 KB |
Output is correct |
40 |
Correct |
3 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 |
0 ms |
208 KB |
Output is correct |
45 |
Correct |
1 ms |
208 KB |
Output is correct |
46 |
Correct |
0 ms |
208 KB |
Output is correct |
47 |
Correct |
0 ms |
208 KB |
Output is correct |
48 |
Correct |
0 ms |
208 KB |
Output is correct |
49 |
Correct |
0 ms |
208 KB |
Output is correct |
50 |
Correct |
0 ms |
208 KB |
Output is correct |
51 |
Correct |
0 ms |
208 KB |
Output is correct |
52 |
Correct |
2 ms |
208 KB |
Output is correct |
53 |
Correct |
2 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 |
1 ms |
208 KB |
Output is correct |
57 |
Correct |
2 ms |
208 KB |
Output is correct |
58 |
Correct |
1 ms |
208 KB |
Output is correct |
59 |
Correct |
3 ms |
208 KB |
Output is correct |
60 |
Correct |
3 ms |
208 KB |
Output is correct |
61 |
Correct |
3 ms |
208 KB |
Output is correct |
62 |
Correct |
3 ms |
208 KB |
Output is correct |
63 |
Correct |
2 ms |
208 KB |
Output is correct |
64 |
Correct |
2 ms |
208 KB |
Output is correct |
65 |
Correct |
0 ms |
208 KB |
Output is correct |
66 |
Correct |
18 ms |
336 KB |
Output is correct |
67 |
Correct |
25 ms |
336 KB |
Output is correct |
68 |
Correct |
6 ms |
336 KB |
Output is correct |
69 |
Correct |
29 ms |
336 KB |
Output is correct |
70 |
Correct |
11 ms |
208 KB |
Output is correct |
71 |
Correct |
25 ms |
336 KB |
Output is correct |
72 |
Correct |
15 ms |
208 KB |
Output is correct |
73 |
Correct |
33 ms |
336 KB |
Output is correct |
74 |
Correct |
35 ms |
336 KB |
Output is correct |
75 |
Correct |
26 ms |
336 KB |
Output is correct |
76 |
Correct |
37 ms |
336 KB |
Output is correct |
77 |
Correct |
29 ms |
336 KB |
Output is correct |
78 |
Correct |
25 ms |
336 KB |
Output is correct |
79 |
Correct |
0 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 |
208 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 |
0 ms |
208 KB |
Output is correct |
88 |
Correct |
1 ms |
208 KB |
Output is correct |
89 |
Correct |
1 ms |
208 KB |
Output is correct |
90 |
Correct |
2 ms |
208 KB |
Output is correct |
91 |
Correct |
2 ms |
208 KB |
Output is correct |
92 |
Correct |
2 ms |
208 KB |
Output is correct |
93 |
Correct |
3 ms |
208 KB |
Output is correct |
94 |
Correct |
0 ms |
208 KB |
Output is correct |
95 |
Correct |
0 ms |
208 KB |
Output is correct |
96 |
Correct |
1 ms |
208 KB |
Output is correct |
97 |
Correct |
0 ms |
284 KB |
Output is correct |
98 |
Correct |
0 ms |
208 KB |
Output is correct |
99 |
Correct |
0 ms |
208 KB |
Output is correct |
100 |
Correct |
1 ms |
208 KB |
Output is correct |
101 |
Correct |
1 ms |
208 KB |
Output is correct |
102 |
Correct |
4 ms |
208 KB |
Output is correct |
103 |
Correct |
28 ms |
336 KB |
Output is correct |
104 |
Correct |
31 ms |
336 KB |
Output is correct |
105 |
Correct |
26 ms |
336 KB |
Output is correct |
106 |
Correct |
39 ms |
336 KB |
Output is correct |
107 |
Correct |
35 ms |
336 KB |
Output is correct |
108 |
Correct |
0 ms |
208 KB |
Output is correct |
109 |
Correct |
1 ms |
208 KB |
Output is correct |
110 |
Correct |
17 ms |
336 KB |
Output is correct |
111 |
Correct |
25 ms |
336 KB |
Output is correct |
112 |
Correct |
19 ms |
336 KB |
Output is correct |
113 |
Correct |
27 ms |
336 KB |
Output is correct |
114 |
Correct |
25 ms |
336 KB |
Output is correct |
115 |
Correct |
0 ms |
208 KB |
Output is correct |
116 |
Correct |
1 ms |
208 KB |
Output is correct |
117 |
Correct |
1 ms |
336 KB |
Output is correct |
118 |
Correct |
1 ms |
336 KB |
Output is correct |
119 |
Correct |
1 ms |
336 KB |
Output is correct |
120 |
Correct |
1 ms |
336 KB |
Output is correct |
121 |
Correct |
1 ms |
336 KB |
Output is correct |
122 |
Correct |
0 ms |
208 KB |
Output is correct |
123 |
Correct |
0 ms |
208 KB |
Output is correct |
124 |
Correct |
0 ms |
208 KB |
Output is correct |
125 |
Correct |
0 ms |
208 KB |
Output is correct |
126 |
Runtime error |
17 ms |
2976 KB |
Execution killed with signal 11 |
127 |
Halted |
0 ms |
0 KB |
- |