# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
138828 | dnass | Scales (IOI15_scales) | C++14 | 0 ms | 0 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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
int n, k, l;
vector<int> lhalf, rhalf;
int lsize, rsize;
vector<lld> beg_l, beg_r, new_beg_r;
lld min_new_beg_r_mod_k[10000002];
int myceil(int x, int y){
if(x%y==0) return x/y;
return (x/y)+1;
}
long long delivery(int N, int K, int L, int p[]){
lld cost = 1e18;
n = N; k = K; l = L;
if(n==1) return min((lld)2*p[0], (lld)2*(l-p[0]));
for(int i=0;i<n&&2*p[i]<=l;i++){
lhalf.push_back(p[i]);
}
lsize = (int) lhalf.size();
for(int i=n-1;i>=0&&2*(l-p[i])<l;i--){
rhalf.push_back(l-p[i]);
}
rsize = (int) rhalf.size();
beg_l.push_back(0);
for(int i=0;i<lsize;i++){
beg_l.push_back(2*((lld)lhalf[i])+beg_l[max(0, i-k+1)]);
}
beg_r.push_back(0);
for(int i=0;i<rsize;i++){
beg_r.push_back(2*((lld)rhalf[i])+beg_r[max(0, i-k+1)]);
}
cost = *beg_l.rbegin()+*beg_r.rbegin();
for(int i=rsize;i>=0;i--){
new_beg_r.push_back(beg_r[i]+(lld)myceil(rsize-i, k)*((lld) l));
}
/*
for(auto x:beg_r) printf("%lld ", x);
printf("\n");
for(auto x:new_beg_r) printf("%lld ", x);
printf("\n");
for(auto x:beg_l) printf("%lld ", x);
printf("\n");
*/
for(int i=0;i<k;i++){
min_new_beg_r_mod_k[i] = 1e18;
}
for(int i=0;i<=rsize;i++){
min_new_beg_r_mod_k[i%k] = min(min_new_beg_r_mod_k[i%k], new_beg_r[i]);
}
for(int i=lsize;i>=0;i--){
cost = min(cost, ((lld)((lsize-i)/k))*((lld)l)+min_new_beg_r_mod_k[(k-((lsize-i)%k))%k]+beg_l[i]);
}
return cost;
}