Submission #76856

#TimeUsernameProblemLanguageResultExecution timeMemory
76856VardanyanStove (JOI18_stove)C++14
20 / 100
581 ms209388 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5007; long long a[N]; long long dp[N][N]; int main(){ int n,k; scanf("%d%d",&n,&k); queue<pair<int,int> > q; for(int i = 1;i<=n;i++){ if(i>1) q.push({i,1}); scanf("%lld",&a[i]); for(int j = 0;j<=k;j++) dp[i][j] = 100000000000000005; } for(int kk = 1;kk<=k;kk++){ dp[1][kk] = 1; /*for(int i = 2;i<=n;i++){ dp[i][kk] = min(dp[i][kk],dp[i-1][kk]+((a[i]+1)-(a[i-1]+1))); dp[i][kk+1] = min(dp[i][kk+1],dp[i-1][kk]+1); }*/ while(!q.empty()){ pair<int,int> x = q.front(); if(x.second>kk) break; q.pop(); int i = x.first; long long u = dp[i-1][kk]+((a[i]+1)-(a[i-1]+1)); if(dp[i][kk]>u){ dp[i][kk] = u; q.push({i+1,kk+1}); } u = dp[i-1][kk]+1; if(dp[i][kk+1]>u){ dp[i][kk+1] = u; q.push({i+1,kk+1}); } } } printf("%lld\n",dp[n][k]); return 0; }

Compilation message (stderr)

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