이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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=0;i<=5000;i++){
}
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |