# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
771295 | caganyanmaz | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 212 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 <bits/stdc++.h>
#define pb push_back
using namespace std;
long long delivery(int N, int K, int L, int positions[])
{
vector<long long> lpos, rpos;
int middle = 0;
for (int i = 0; i < N; i++)
if (positions[i] < (L / 2))
lpos.pb(positions[i]);
else if (positions[i] > (L / 2))
rpos.pb(-positions[i]);
else
middle++;
sort(lpos.begin(), lpos.end());
sort(rpos.begin(), rpos.end());
vector<int> ldp(lpos.size()+1), rdp(rpos.size()+1);
for (int i = 1; i <= lpos.size(); i++)
{
if (i >= K)
ldp[i] += ldp[i-K];
ldp[i] += static_cast<long long>(lpos[i-1]) * 2;
}
for (int i = 1; i <= rpos.size(); i++)
{
if (i >= K)
rdp[i] += rdp[i-K];
rdp[i] += static_cast<long long>(L+rpos[i-1]) * 2;
}
long long result = ldp[lpos.size()] + rdp[rpos.size()] + (middle / K) * L;
if (middle%K)
result += L;
for (int i = 1; i <= 4; i++)
{
long long remainder = K * i + (middle % K);
for (int lremainder = 0; lremainder <= remainder; lremainder++)
result = min(result, ldp[lpos.size()-lremainder] + rdp[rpos.size()-remainder+lremainder] + ((middle + remainder) / K) * L);
}
return result;
}
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... |