// 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[maxx], dp[maxx][maxn] ;
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 ;
for(int j = 0 ; j <= alt + min(m, 200) ; j++){
if(v[i] == j) ans = min(ans, solve(i+1, j)) ;
else ans = min(ans, solve(i+1, j) + 1) ;
}
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] ;
memset(dp, -1, sizeof dp) ;
cout << solve(1, 0) << "\n" ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
17 ms |
708 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
13 ms |
708 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
596 KB |
Output is correct |
2 |
Correct |
0 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
0 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
0 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
17 ms |
708 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
13 ms |
708 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
596 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |