제출 #926566

#제출 시각아이디문제언어결과실행 시간메모리
926566Aiperiii다리 (APIO19_bridges)C++14
0 / 100
670 ms399268 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...