# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1123323 | ezzzay | Rabbit Carrot (LMIO19_triusis) | C++20 | 77 ms | 584 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;
dp[0]=0;
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]);
}
dp[0]=1e9;
int ans=n;
for(int i=1;i<=n;i++){
for(int hi=0;hi<=5005;hi++){
// hi-k aas bagaas doosh +1
// busad ni 0
if(hi-k-1>=0){
dp[hi]=ps[hi-k-1]+1;
}
dp[hi]= min(dp[hi],sf[max(0LL,hi-k)]);
}
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;
}
}
for(int i=0;i<=5000;i++){
ans=min(ans,dp[i]);
}
cout<<ans;
}
Compilation message (stderr)
# | 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... |