# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
76856 | Vardanyan | Stove (JOI18_stove) | C++14 | 581 ms | 209388 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |