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;
#define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll
int p1[10000010], p2[10000010];
long long delivery(int32_t N, int32_t K, int32_t L, int32_t p[]) {
int n=N, k=K, l=L;
int ac=k;
int cr=0;
for(int i=0; i<n; i++){
if(p[i]>0){ac--;}
if(ac==0){
cr=cr+p[i]*2; p1[i]=cr;
ac=k;
}
else{
p1[i]=cr+p[i]*2;
}
}
cr=0; ac=k;
for(int i=n-1; i>=0; i--){
if(p[i]>0){ac--;}
if(ac==0){
cr=cr+(l-p[i])*2; p2[i]=cr;
ac=k;
}
else{
p2[i]=cr+(l-p[i])*2;
}
}
int mn=1e17; mn=mn*10;
mn=min(mn, p2[0]);
for(int i=0; i<n; i++){
mn=min(p1[i]+p2[i+1], mn);
}
for(int i=-1; i<n; i++){
for(int j=i+1; j<n; j++){
mn=min( ((i>=0)?(p1[i]):(0))+p2[j]+( ( (j-i-1)/k+( ( ((j-i-1)%k)>0 )?(1):(0) ) )*l ), mn );
}
}
for(int i=0; i<n; i++){
mn=min(mn, p2[i]+( ( (i/k)+( ( (i%k)>0 )?(1):(0) ) )*l ));
mn=min(mn, p1[i]+( ( (n-i-1)/k+( ( ((n-i-1)%k)>0 )?(1):(0) ) )*l ) );
}
for(int i=0; i<n; i++){
if( (i-k)>=0 ){
mn=min(p2[i+1]+p1[i-k]+l, mn);
}
mn=min(p2[i+1]+( (i+1)/k+(((i+1)%k)?(1):(0)) )*l, mn);
mn=min(mn, p1[i]+( (n-i-1)/k+( ((n-i-1)%k)?(1):(0) ) )*l );
}
mn=min(mn, ( (n/k)+ ( ((n%k)>0 )?(1):(0) ) )*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... |