#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
const int N=5e3+5;
int dp[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,m;
cin>>n>>m;
vector <int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
for(int i=0;i<=5000;i++){
if(i!=a[0])dp[0][i]=1;
if(i>m)dp[0][i]=1e9;
}
for(int i=1;i<n;i++){
int mn=1e9;
int ind=5000-m;
for(int j=5000;j>=ind;j--){
mn=min(mn,dp[i-1][j]);
}
for(int j=5000;j>=0;j--){
if(j!=a[i])dp[i][j]=mn+1;
else dp[i][j]=mn;
ind--;
if(ind>=0)mn=min(mn,dp[i-1][ind]);
}
}
int ans=1e9;
for(int i=0;i<=5000;i++){
ans=min(ans,dp[n-1][i]);
}
cout<<ans<<"\n";
}
/*
5 400
300
700
200
1000
500
3 300
700
1000
1300
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Correct |
1 ms |
2652 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
1 ms |
2652 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
2 ms |
2492 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2652 KB |
Output is correct |
16 |
Correct |
1 ms |
2652 KB |
Output is correct |
17 |
Correct |
1 ms |
2652 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
63 ms |
160536 KB |
Output is correct |
21 |
Correct |
54 ms |
196316 KB |
Output is correct |
22 |
Correct |
49 ms |
196204 KB |
Output is correct |
23 |
Correct |
59 ms |
196176 KB |
Output is correct |
24 |
Correct |
62 ms |
196336 KB |
Output is correct |
25 |
Correct |
49 ms |
196168 KB |
Output is correct |
26 |
Correct |
51 ms |
196436 KB |
Output is correct |
27 |
Correct |
49 ms |
196180 KB |
Output is correct |
28 |
Correct |
49 ms |
196136 KB |
Output is correct |
29 |
Correct |
54 ms |
196180 KB |
Output is correct |
30 |
Correct |
50 ms |
196192 KB |
Output is correct |
31 |
Correct |
48 ms |
196176 KB |
Output is correct |
32 |
Correct |
55 ms |
196176 KB |
Output is correct |
33 |
Correct |
55 ms |
196176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
63 ms |
160536 KB |
Output is correct |
5 |
Correct |
54 ms |
196316 KB |
Output is correct |
6 |
Correct |
49 ms |
196204 KB |
Output is correct |
7 |
Correct |
59 ms |
196176 KB |
Output is correct |
8 |
Correct |
62 ms |
196336 KB |
Output is correct |
9 |
Correct |
49 ms |
196168 KB |
Output is correct |
10 |
Correct |
51 ms |
196436 KB |
Output is correct |
11 |
Correct |
49 ms |
196180 KB |
Output is correct |
12 |
Correct |
49 ms |
196136 KB |
Output is correct |
13 |
Correct |
54 ms |
196180 KB |
Output is correct |
14 |
Correct |
50 ms |
196192 KB |
Output is correct |
15 |
Correct |
48 ms |
196176 KB |
Output is correct |
16 |
Correct |
55 ms |
196176 KB |
Output is correct |
17 |
Correct |
55 ms |
196176 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
2652 KB |
Output is correct |
22 |
Correct |
1 ms |
2652 KB |
Output is correct |
23 |
Correct |
1 ms |
2652 KB |
Output is correct |
24 |
Correct |
1 ms |
2652 KB |
Output is correct |
25 |
Correct |
1 ms |
2652 KB |
Output is correct |
26 |
Correct |
1 ms |
2652 KB |
Output is correct |
27 |
Correct |
1 ms |
2652 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2648 KB |
Output is correct |
30 |
Correct |
2 ms |
2492 KB |
Output is correct |
31 |
Correct |
1 ms |
2652 KB |
Output is correct |
32 |
Correct |
1 ms |
2652 KB |
Output is correct |
33 |
Correct |
1 ms |
2652 KB |
Output is correct |
34 |
Correct |
51 ms |
196180 KB |
Output is correct |
35 |
Incorrect |
64 ms |
196180 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
51 ms |
196180 KB |
Output is correct |
2 |
Incorrect |
64 ms |
196180 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |