# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
163009 | kostia244 | Boxes with souvenirs (IOI15_boxes) | C++14 | 10 ms | 380 KiB |
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>
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
ll n, k, l;
vi pos, dpl, dpr;
ll getl(ll x) {
return min(2ll*x, l);
}
ll getr(ll x) {
return min(2ll*(l-x), l);
}
long long delivery(int N, int K, int L, int P[]) {
n=N, k = K, l = L;
ll ans = LLONG_MAX;
pos.resize(n+2);
dpl.resize(n+2);
dpr.resize(n+2);
for(int i = 0; i < n; i++)
pos[i+1] = P[i];
for(int i = 1; i <= n; i++) {
if((i-1)%k==0) {
dpl[i] = dpl[i-1]+getl(pos[i]);
} else {
dpl[i] = dpl[i-1]-getl(pos[i-1])+getl(pos[i]);
}
}
for(int i = n; i; i--) {
if((n-i)%k==0) {
dpr[i] = dpr[i+1]+getr(pos[i]);
} else {
dpr[i] = dpr[i+1]-getr(pos[i+1])+getr(pos[i]);
}
}
for(int i = 0; i <= n; i++) {
ans = min(ans, dpl[i]+dpr[i+1]);
// cout << i << " " << dpl[i] << " " << dpr[i+1] << "\n";
}
return ans;
}
Compilation message (stderr)
# | 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... |