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 <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <iostream>
#include "boxes.h"
#define ll long long
#define ve vector
using namespace std;
int dst(int x, int L){
return min(x, L - x);
}
long long delivery(int N, int K, int L, int p[]) {
int cnt0 = 0;
for(int i = 0; i < N; i++)
cnt0 += p[i] == 0;
N -= cnt0;
ve<ll> dpl(N), dpr(N);
dpl[0] = p[0];
for(int i = 0; i < N; i++)
p[i] = p[i + cnt0];
int cnt = 1;
for(int i = 1; i < N; i++){
dpl[i] = dpl[i - 1] + p[i] - p[i - 1];
cnt++;
if(cnt == K + 1){
dpl[i] += 2*p[i - 1];
cnt = 1;
}
}
cnt = 1;
dpr[N - 1] = L - p[N - 1];
for(int i = N - 2; i >= 0; i--){
dpr[i] = dpr[i + 1] + p[i + 1] - p[i];
cnt++;
if(cnt == K + 1){
dpr[i] += 2*(L - p[i + 1]);
cnt = 1;
}
}
ll res = min(dpl[N - 1] + dst(p[N - 1], L), dpr[0] + dst(p[0], L));
for(int i = 0; i < N - 1; i++)
res = min(res, dpl[i] + dst(p[i], L) + dpr[i + 1] + dst(p[i + 1], L));
return res;
}
# | 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... |