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 <bits/stdc++.h>
#include "boxes.h"
using namespace std;
typedef long long ll;
ll left(int n, int k, int l, vector<ll> p) {
ll sum = 0;
ll pos = 0;
for (int i = 0; i < n; i++) {
sum += min(abs(p[i]-pos), l-abs(p[i]-pos));
pos = p[i];
if ((i+1) % k == 0) {
sum += min(pos, l-pos);
pos = 0;
}
}
return sum + min(pos, l-pos);
}
ll right(int n, int k, int l, vector<ll> p) {
reverse(p.begin(), p.end());
ll sum = 0;
ll pos = 0;
for (int i = 0; i < n; i++) {
sum += min(abs(p[i]-pos), l-abs(p[i]-pos));
pos = p[i];
if ((i+1) % k == 0) {
sum += min(pos, l-pos);
pos = 0;
}
}
return sum + min(pos, l-pos);
}
ll delivery(int n, int k, int l, int p11[]) {
vector<ll> p(n);
for (int i = 0; i < n; i++) p[i] = p11[i];
return min(left(n, k, l, p), right(n, k, l, p));
}
# | 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... |