Submission #1123332

#TimeUsernameProblemLanguageResultExecution timeMemory
1123332ezzzayRabbit Carrot (LMIO19_triusis)C++20
0 / 100
91 ms584 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=5005; int dp[N]; int tmp[N]; int a[N]; int ps[N]; int sf[N]; signed main(){ for(int i=0;i<N;i++){ dp[i]=1e9; tmp[i]=1e9; } int n,k; cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i]; tmp[0]=0; ps[0]=tmp[0]; for(int j=1;j<=5000;j++){ ps[j]=min(ps[j-1],tmp[j]); } sf[5001]=1e9; for(int j=5000;j>=0;j--){ sf[j]=min(sf[j+1],tmp[j]); } int ans=n; for(int i=1;i<=n;i++){ for(int hi=0;hi<=5000;hi++){ // hi-k aas bagaas doosh +1 // busad ni 0 if(hi==a[i]){ dp[hi]=min(dp[hi],sf[max(0LL,hi-k)]); } else{ if(hi-k-1>=0){ dp[hi]=ps[hi-k-1]+1; } dp[hi]=min(dp[hi],sf[max(0LL,hi-k)]+1); } if(i==n)ans=min(ans,dp[hi]); } ps[0]=dp[0]; for(int j=1;j<=5000;j++){ ps[j]=min(ps[j-1],dp[j]); } sf[5001]=1e9; for(int j=5000;j>=0;j--){ sf[j]=min(sf[j+1],dp[j]); } for(int j=0;j<=5000;j++){ tmp[j]=dp[j]; dp[j]=1e9; } } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...