#include <iostream>
#include <set>
using namespace std;
const int MAXN = 5010;
int ans = 1e9;
int dp[MAXN][MAXN];
int arr[MAXN];
int pref[MAXN];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>arr[i];
}
for(int i=0;i<=5000;i++){
if(i == 0){
dp[0][i] = 0;
}else{
dp[0][i] = 1e8;
}
}
pref[5001] = 1e9;
for(int j=5000;j>=0;j--){
pref[j] = 1e9;
pref[j] = min(pref[j+1],dp[0][j]);
}
for(int i=1;i<=n;i++){
for(int j=0;j<=5000;j++){
int lptr = j-m-1;
// cout<<j<<endl;
int hold = pref[0];
if(lptr>=0){
hold = pref[lptr+1];
}
dp[i][j] = (int)hold;
if(arr[i] !=j){
dp[i][j]++;
}else{
// cout<<arr[i]<<endl;
}
}
pref[5001] = 1e9;
for(int j=5000;j>=0;j--){
pref[j] = 1e9;
pref[j] = min(pref[j+1],dp[i][j]);
}
}
//cout<<dp[3][700]<<endl;
for(int i=0;i<=5000;i++){
ans = min(ans,dp[n][i]);
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
632 KB |
Output is correct |
9 |
Correct |
2 ms |
632 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
13 |
Correct |
2 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
508 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
163 ms |
79732 KB |
Output is correct |
5 |
Correct |
195 ms |
98436 KB |
Output is correct |
6 |
Correct |
187 ms |
98476 KB |
Output is correct |
7 |
Correct |
191 ms |
98424 KB |
Output is correct |
8 |
Correct |
189 ms |
98552 KB |
Output is correct |
9 |
Correct |
188 ms |
98476 KB |
Output is correct |
10 |
Correct |
187 ms |
98424 KB |
Output is correct |
11 |
Correct |
187 ms |
98424 KB |
Output is correct |
12 |
Correct |
187 ms |
98480 KB |
Output is correct |
13 |
Correct |
239 ms |
98424 KB |
Output is correct |
14 |
Correct |
201 ms |
98424 KB |
Output is correct |
15 |
Correct |
193 ms |
98516 KB |
Output is correct |
16 |
Correct |
190 ms |
98428 KB |
Output is correct |
17 |
Correct |
189 ms |
98424 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
632 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
632 KB |
Output is correct |
26 |
Correct |
2 ms |
632 KB |
Output is correct |
27 |
Correct |
2 ms |
504 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
2 ms |
504 KB |
Output is correct |
30 |
Correct |
2 ms |
504 KB |
Output is correct |
31 |
Correct |
2 ms |
508 KB |
Output is correct |
32 |
Correct |
3 ms |
504 KB |
Output is correct |
33 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
98364 KB |
Output is correct |
2 |
Incorrect |
189 ms |
98412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
192 ms |
98364 KB |
Output is correct |
2 |
Incorrect |
189 ms |
98412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |