# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
968606 | alex_2008 | Boxes with souvenirs (IOI15_boxes) | C++14 | 494 ms | 250528 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 <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;
ll delivery(int n, int k, int l, int pos[]) {
vector <int> a, b;
vector <ll> dp_a, dp_b;
for (int i = 0; i < n; i++) {
if (pos[i] <= (l / 2)) a.push_back(pos[i]);
else b.push_back(pos[i]);
}
reverse(b.begin(), b.end());
for (auto &it : b) {
it = l - it;
}
dp_a.resize((int)a.size());
dp_b.resize((int)b.size());
for (int i = 0; i < (int)dp_a.size(); i++) {
if (i < k) {
dp_a[i] = 2 * a[i];
}
else {
dp_a[i] = dp_a[i - k] + 2 * a[i];
}
}
for (int i = 0; i < (int)dp_b.size(); i++) {
if (i < k) {
dp_b[i] = 2 * b[i];
}
else {
dp_b[i] = dp_b[i - k] + 2 * b[i];
}
}
int ind1 = 0, ind2 = 0;
ll ans = (((int)dp_a.size() > 0) ? dp_a.back(): 0) + (((int)dp_b.size() > 0) ? dp_b.back(): 0);
for (int i = 0; i < (int)dp_a.size(); i++) {
ll cur = 0;
if (i) cur += dp_a[i - 1];
int mnac = (int)dp_a.size() - i;
cur = cur + (mnac + k - 1) / k * 1ll * l;
int w = ((mnac + k - 1) / k) * k + i;
if (w < (int)dp_a.size() + (int)dp_b.size()) {
cur += dp_b[(int)dp_b.size() + (int)dp_a.size() - w - 1];
}
ans = min(ans, cur);
}
return ans;
}
/*
int main() {
int n, k, l;
cin >> n >> k >> l;
vector <int> v(n);
for (auto &it : v) {
cin >> it;
}
cout << delivery(n, k, l, v) << "\n";
}*/
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... |