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 LL;
const LL INF=1e18;
LL dist(LL x,LL y,LL mod){
return min((y-x+mod)%mod,(x-y+mod)%mod);
}
LL cost(LL a,LL b,LL mod){
return dist(a,0,mod)+(b-a+mod)%mod+dist(b,0,mod);
}
LL delivery(int N, int K, int L, int p[]) {
LL sisa=N%K,ans=INF;
for(LL i=0;i<=sisa;i++){
//i di kiri, sisa-i di kanan
LL ret=0;
if(i!=0)ret+=cost(p[0],p[i-1],L);
for(LL j=1;j<=N/K;j++)ret+=cost(p[i+(j-1)*K],p[i+j*K-1],L);
if(sisa-i!=0)ret+=cost(p[N-sisa+i],p[N-1],L);
ans=min(ans,ret);
}
return ans;
}
# | 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... |