Submission #1123323

#TimeUsernameProblemLanguageResultExecution timeMemory
1123323ezzzayRabbit Carrot (LMIO19_triusis)C++20
0 / 100
77 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;
    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)

triusis.cpp: In function 'int main()':
triusis.cpp:43:19: warning: iteration 5005 invokes undefined behavior [-Waggressive-loop-optimizations]
   43 |             dp[hi]= min(dp[hi],sf[max(0LL,hi-k)]);
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
triusis.cpp:37:24: note: within this loop
   37 |         for(int hi=0;hi<=5005;hi++){
      |                      ~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...