Submission #547310

#TimeUsernameProblemLanguageResultExecution timeMemory
547310krit3379K blocks (IZhO14_blocks)C++17
0 / 100
1 ms340 KiB
#include<bits/stdc++.h> using namespace std; #define N 100005 int a[N],l[N],dp[105][N]; int main(){ int n,k,i,j; scanf("%d %d",&n,&k); a[0]=2e9; for(i=1;i<=n;i++){ scanf("%d",&a[i]); l[i]=i-1; while(a[i]>a[l[i]])l[i]=l[l[i]]; } for(i=0;i<=k;i++)for(j=0;j<=n;j++)dp[i][j]=1e9; for(i=1;i<=n;i++){ if(l[i]==0)dp[1][i]=a[i]; dp[1][i]=min(dp[1][i],dp[1][l[i]]); } for(i=2;i<=k;i++){ for(j=i;j<=n;j++){ dp[i][j]=min({dp[i][j],dp[i][l[j]],dp[i-1][l[j]+1]+a[j],dp[i-1][j-1]+a[j]}); } } printf("%d",dp[k][n]); return 0; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
blocks.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...