// pra cada cara a gnt sabe o intervalo q ele pode precisar
// v[i] - m (sair dele p esse) ou
// dp[i][s] -> min qtd de descidas q eu preciso
// p com s subidas chegar em i
// tem um intervalo p cada cara mas isso depende dos anteriores
// dp[i][alt] = min de ops q eu preciso fzr para que esteja ok
// chegar em i com o ultimo tendo altura alt
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 5e3 + 5 ;
const int maxx = 20 ;
int n, m, v[maxn], dp[maxn][maxn], mx ;
int solve(int i, int alt){
// cout << i << " " << alt << "\n" ;
if(i > n) return 0 ;
if(dp[i][alt] != -1) return dp[i][alt] ;
int ans = maxn ;
int op1 = alt + m, op2 = v[i] ;
ans = min({ans, solve(i+1, op1) + 1, solve(i+1, 0) + 1}) ;
if(v[i] <= alt + m) ans = min(ans, solve(i+1, op2)) ;
return dp[i][alt] = ans ;
}
int main(){
ios_base::sync_with_stdio(false) ; cin.tie(NULL) ;
cin >> n >> m ;
for(int i = 1 ; i <= n ; i++) cin >> v[i] ;
for(int i = 1 ; i <= n ; i++) mx = max(mx, v[i]) ;
for(int i = 0 ; i <= n ; i++) v[i] += mx ;
memset(dp, -1, sizeof dp) ;
cout << solve(1, mx) << "\n" ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
98252 KB |
Output is correct |
2 |
Correct |
36 ms |
98284 KB |
Output is correct |
3 |
Correct |
36 ms |
98264 KB |
Output is correct |
4 |
Correct |
36 ms |
98340 KB |
Output is correct |
5 |
Correct |
35 ms |
98260 KB |
Output is correct |
6 |
Correct |
39 ms |
98268 KB |
Output is correct |
7 |
Correct |
34 ms |
98260 KB |
Output is correct |
8 |
Correct |
38 ms |
98256 KB |
Output is correct |
9 |
Correct |
35 ms |
98252 KB |
Output is correct |
10 |
Correct |
36 ms |
98272 KB |
Output is correct |
11 |
Correct |
34 ms |
98260 KB |
Output is correct |
12 |
Correct |
35 ms |
98264 KB |
Output is correct |
13 |
Correct |
36 ms |
98252 KB |
Output is correct |
14 |
Correct |
35 ms |
98252 KB |
Output is correct |
15 |
Correct |
35 ms |
98340 KB |
Output is correct |
16 |
Correct |
37 ms |
98324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
98252 KB |
Output is correct |
2 |
Correct |
36 ms |
98284 KB |
Output is correct |
3 |
Correct |
36 ms |
98264 KB |
Output is correct |
4 |
Correct |
36 ms |
98340 KB |
Output is correct |
5 |
Correct |
35 ms |
98260 KB |
Output is correct |
6 |
Correct |
39 ms |
98268 KB |
Output is correct |
7 |
Correct |
34 ms |
98260 KB |
Output is correct |
8 |
Correct |
38 ms |
98256 KB |
Output is correct |
9 |
Correct |
35 ms |
98252 KB |
Output is correct |
10 |
Correct |
36 ms |
98272 KB |
Output is correct |
11 |
Correct |
34 ms |
98260 KB |
Output is correct |
12 |
Correct |
35 ms |
98264 KB |
Output is correct |
13 |
Correct |
36 ms |
98252 KB |
Output is correct |
14 |
Correct |
35 ms |
98252 KB |
Output is correct |
15 |
Correct |
35 ms |
98340 KB |
Output is correct |
16 |
Correct |
37 ms |
98324 KB |
Output is correct |
17 |
Correct |
35 ms |
98260 KB |
Output is correct |
18 |
Correct |
37 ms |
98312 KB |
Output is correct |
19 |
Correct |
35 ms |
98332 KB |
Output is correct |
20 |
Correct |
265 ms |
98680 KB |
Output is correct |
21 |
Correct |
158 ms |
98740 KB |
Output is correct |
22 |
Correct |
36 ms |
98636 KB |
Output is correct |
23 |
Runtime error |
112 ms |
200032 KB |
Execution killed with signal 11 |
24 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
98260 KB |
Output is correct |
2 |
Correct |
37 ms |
98312 KB |
Output is correct |
3 |
Correct |
35 ms |
98332 KB |
Output is correct |
4 |
Correct |
265 ms |
98680 KB |
Output is correct |
5 |
Correct |
158 ms |
98740 KB |
Output is correct |
6 |
Correct |
36 ms |
98636 KB |
Output is correct |
7 |
Runtime error |
112 ms |
200032 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
98260 KB |
Output is correct |
2 |
Correct |
37 ms |
98312 KB |
Output is correct |
3 |
Correct |
35 ms |
98332 KB |
Output is correct |
4 |
Correct |
265 ms |
98680 KB |
Output is correct |
5 |
Correct |
158 ms |
98740 KB |
Output is correct |
6 |
Correct |
36 ms |
98636 KB |
Output is correct |
7 |
Runtime error |
112 ms |
200032 KB |
Execution killed with signal 11 |
8 |
Halted |
0 ms |
0 KB |
- |