#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n + 1];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
n++;
int dp[n + 1];
dp[n - 1] = dp[n] = 0;
for (int i = n - 2; i >= 0; i--) {
dp[i] = 1e9;
if (a[i] >= a[i + 1] || a[i + 1] - a[i] <= m) {
dp[i] = dp[i + 1];
}
for (int j = i + 1; j < n; j++) {
if (j == n - 1 || a[j + 1] <= a[i] + 2 * m) {
dp[i] = min(dp[i], dp[j + 1] + j - i);
}
}
for (int j = i; j < n; j++) {
if (j == n - 1 || a[i] - i * m >= a[j + 1] - j * m || a[j + 1] - j * m <= a[i] - i * m + m) {
dp[i] = min(dp[i], dp[j + 1] + j - i);
}
}
}
cout << dp[0] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
412 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
756 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
412 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
756 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
51 ms |
348 KB |
Output is correct |
21 |
Correct |
77 ms |
344 KB |
Output is correct |
22 |
Correct |
80 ms |
464 KB |
Output is correct |
23 |
Correct |
77 ms |
344 KB |
Output is correct |
24 |
Correct |
77 ms |
348 KB |
Output is correct |
25 |
Correct |
57 ms |
344 KB |
Output is correct |
26 |
Correct |
70 ms |
464 KB |
Output is correct |
27 |
Correct |
40 ms |
348 KB |
Output is correct |
28 |
Correct |
46 ms |
348 KB |
Output is correct |
29 |
Correct |
77 ms |
348 KB |
Output is correct |
30 |
Correct |
67 ms |
592 KB |
Output is correct |
31 |
Correct |
43 ms |
344 KB |
Output is correct |
32 |
Correct |
77 ms |
344 KB |
Output is correct |
33 |
Correct |
77 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
51 ms |
348 KB |
Output is correct |
5 |
Correct |
77 ms |
344 KB |
Output is correct |
6 |
Correct |
80 ms |
464 KB |
Output is correct |
7 |
Correct |
77 ms |
344 KB |
Output is correct |
8 |
Correct |
77 ms |
348 KB |
Output is correct |
9 |
Correct |
57 ms |
344 KB |
Output is correct |
10 |
Correct |
70 ms |
464 KB |
Output is correct |
11 |
Correct |
40 ms |
348 KB |
Output is correct |
12 |
Correct |
46 ms |
348 KB |
Output is correct |
13 |
Correct |
77 ms |
348 KB |
Output is correct |
14 |
Correct |
67 ms |
592 KB |
Output is correct |
15 |
Correct |
43 ms |
344 KB |
Output is correct |
16 |
Correct |
77 ms |
344 KB |
Output is correct |
17 |
Correct |
77 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
412 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
756 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
79 ms |
348 KB |
Output is correct |
35 |
Correct |
82 ms |
464 KB |
Output is correct |
36 |
Correct |
79 ms |
344 KB |
Output is correct |
37 |
Correct |
64 ms |
348 KB |
Output is correct |
38 |
Correct |
37 ms |
464 KB |
Output is correct |
39 |
Correct |
47 ms |
348 KB |
Output is correct |
40 |
Correct |
43 ms |
348 KB |
Output is correct |
41 |
Correct |
47 ms |
348 KB |
Output is correct |
42 |
Correct |
77 ms |
344 KB |
Output is correct |
43 |
Correct |
77 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
348 KB |
Output is correct |
2 |
Correct |
82 ms |
464 KB |
Output is correct |
3 |
Correct |
79 ms |
344 KB |
Output is correct |
4 |
Correct |
64 ms |
348 KB |
Output is correct |
5 |
Correct |
37 ms |
464 KB |
Output is correct |
6 |
Correct |
47 ms |
348 KB |
Output is correct |
7 |
Correct |
43 ms |
348 KB |
Output is correct |
8 |
Correct |
47 ms |
348 KB |
Output is correct |
9 |
Correct |
77 ms |
344 KB |
Output is correct |
10 |
Correct |
77 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
51 ms |
348 KB |
Output is correct |
15 |
Correct |
77 ms |
344 KB |
Output is correct |
16 |
Correct |
80 ms |
464 KB |
Output is correct |
17 |
Correct |
77 ms |
344 KB |
Output is correct |
18 |
Correct |
77 ms |
348 KB |
Output is correct |
19 |
Correct |
57 ms |
344 KB |
Output is correct |
20 |
Correct |
70 ms |
464 KB |
Output is correct |
21 |
Correct |
40 ms |
348 KB |
Output is correct |
22 |
Correct |
46 ms |
348 KB |
Output is correct |
23 |
Correct |
77 ms |
348 KB |
Output is correct |
24 |
Correct |
67 ms |
592 KB |
Output is correct |
25 |
Correct |
43 ms |
344 KB |
Output is correct |
26 |
Correct |
77 ms |
344 KB |
Output is correct |
27 |
Correct |
77 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
412 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
756 KB |
Output is correct |
42 |
Correct |
0 ms |
348 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Execution timed out |
1084 ms |
1880 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |