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 debug(x) cout<<#x<<" = "<<x<<endl
typedef long long ll;
int A[1000007];
int n;
int L;
ll sumRange(int s,int len)
{
ll cost=0;
int i=0;
int id=0;
while(i<len){
id=(i+s)%n;
if(i==0)
cost+=(ll)min(A[id],L-A[id]);
else{
int dist=abs(A[id]-A[(id+n-1)%n]);
cost+=(ll)min(dist,L-dist);
}
i++;
}
i--;
id=(i+s)%n;
cost+=(ll)min(A[id],L-A[id]);
return cost;
}
long long delivery(int N, int k, int l, int p[]) {
n=N;
L=l;
for(int i=0;i<n;i++){
A[i]=p[i];
}
ll minimum=LLONG_MAX;
for(int s=0;s<n;s++){ //For each possible start
ll cost=0;
if(n%k!=0) cost+=sumRange(s,n%k);
for(int i=n%k;i<n;i+=k){
cost+=sumRange((s+i)%n,k);
}
minimum=min(minimum,cost);
}
return minimum;
}
# | 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... |