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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
vector<long long> dp1,dp2;
vector<vector<long long> > suf;
dp1.resize(N);
dp2.resize(N);
dp1[0] = 2ll*p[0];
for(int i = 1; i < N; i++){
dp1[i] = i >= K ? dp1[i-K] : 0ll;
dp1[i] += 2ll*(long long)p[i];
}
dp2[N-1] = 2ll*(long long)(L-p[N-1]);
for(int i = N-2; i >= 0; i--){
dp2[i] = i+K >= N ? 0ll : dp2[i+K];
dp2[i] += 2ll*(long long)(L-p[i]);
}
for(int i = 0; i < K; i++){
suf.push_back(vector<long long>());
for(int j = 0; K*j+i < N; j++){
suf[i].push_back(0);
}
}
for(int i = 0; i < K; i++){
for(int j = (N-i-1)/K; j >= 0; j--){
suf[i][j] = min((K*(j+1)+i >= N ? (long long)1e18 : suf[i][j+1]),dp2[K*j+i] + (long long)j*(long long)L);
}
}
long long mn = (long long)(N+K-1)/(long long)K*(long long)L;
for(int i = 0; i < N; i++){
mn = min(mn,dp1[i] + (long long)(N-i+K-2)/(long long)K*(long long)L);
mn = min(mn,dp2[i] + (long long)(i+K-1)/(long long)K*(long long)L);
if(i == N-1) continue;
mn = min(mn,dp1[i] + suf[(i+1) % K][(i+1) / K] - (long long)(i+1)/(long long)K*(long long)L);
//for(int j = 0; i+1+j*K < N; j++){
// mn = min(mn,dp1[i] + dp2[i+1+j*K] + (long long)(j)*(long long)L);
//}
}
return mn;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |