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 <vector>
#include <algorithm>
#include <map>
#include <iostream>
#define INF 1'000'000'000'000'000'000
std::vector<long long> people;
long long l;
inline long long dist(long long curr, long long next = 0)
{
long long d = std::abs(people[curr] - people[next]);
return std::min(d, l - d);
}
long long delivery(int N, int K, int L, int p[])
{
l = L;
people.resize(N+2);
people[0] = 0;
for (int i = 0; i < N; ++i)
people[i+1] = p[i];
people[N+1] = 0;
long long root[N+2]{};
long long next[N+2]{};
long long kDist[N+2]{};
for (int i = 0; i <= N; ++i)
root[i] = dist(i),
next[i] = dist(i, i + 1);
for (int i = N; i >= 0; --i)
kDist[i] = kDist[i+1] + next[i] - (i+K-1 <= N+1 ? next[i+K-1] : 0);
long long best = INF;
for (int i = 1; i <= K; ++i)
{
long long sum = 0;
int pos = 0;
for (int j = 0; j < i; ++j)
{
sum += next[pos];
++pos;
}
while (pos <= N)
{
sum += root[pos];
sum += root[++pos];
sum += kDist[pos];
pos += K-1;
}
best = std::min(best, sum);
}
return best;
}
# | 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... |