# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
680849 | speedyArda | 선물상자 (IOI15_boxes) | C++14 | 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 "boxes.h"
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
long long delivery(int N, int K, int L, int p[]) {
ll pos = 0;
while(p[pos] == 0 && pos < N)
pos++;
if(pos == N)
return 0;
ll ans = 1e18;
//ll temp = 0;
ll t_pos = 0;
ll take = 0;
while(t_pos < N && p[t_pos] <= L / 2)
{
take++;
t_pos++;
}
ll oldtake = take;
ll r_pos = N - 1;
ll toadd = 0;
ll last_l = t_pos - 1;
int other = 0;
while(last_l >= 0)
{
//cout << last_l << "\n";
toadd += p[last_l] * 2LL;
last_l -= K;
}
ll last_r = t_pos;
while(last_r < N)
{
toadd += (L - p[last_r]) * 2LL;
//cout << L << " " << p[last_r] << "\n";
last_r += K;
}
//cout << temp << " " << toadd << " " << p[last_r] << " " << last_r << " " << p[last_r]<< "\n";
ans = min(ans, toadd);
// Go to other half
toadd = 0;
take = oldtake;
while(take < K && t_pos < N)
{
t_pos++;
take++;
}
//cout << t_pos << " " << take << "\n";
last_l = t_pos - 1;
if(take > 0) {
toadd += (ll)L;
last_l -= K;
}
while(last_l >= 0)
{
toadd += p[last_l] * 2LL;
last_l -= K;
}
last_r = t_pos;
if(last_r < N && ((last_r - 1) % K + (L - last_r) % K) == K && p[t_pos] == p[t_pos - 1])
toadd -= (ll)L;
while(last_r < N)
{
toadd += (L - p[last_r]) * 2LL;
last_r += K;
}
//cout << temp << " " << toadd << " " << t_pos << " " << p[t_pos] << "\n";
//cout << temp << " " << toadd << "\n";
ans = min(ans, toadd);
//Begin with right side
r_pos = N - 1;
take = 0;
//toadd = 0;
while(r_pos >= 0 && p[r_pos] >= (L+1) / 2)
{
take++;
r_pos--;
}
oldtake = take;
other = 0;
//Begin with right side
// Don't go to other half
//l_pos = ;
toadd = 0;
last_l = r_pos;
last_r = r_pos + 1;
while(last_l >= 0)
{
toadd += p[last_l] * 2LL;
last_l -= K;
//if(last_l)
//other = last_l;
}
while(last_r < N)
{
toadd += (L - p[last_r]) * 2LL;
last_r += K;
}
//cout << temp << " " << toadd << " " << p[r_pos] << " " << r_pos << "\n";
ans = min(ans, toadd);
//int l_pos = pos;
toadd = 0;
take = oldtake;
while(r_pos >= 0 && take < K)
{
//l_pos += K;
take++;
r_pos--;
}
last_l = r_pos;
last_r = r_pos + 1;
if(take > 0) {
toadd += (ll)L;
last_r += K;
}
while(last_r < N)
{
toadd += (L - p[last_r]) * 2LL;
last_r += K;
}
if(last_l >= 0 && ((L - (last_l + 1)) % K + (last_l) % K) == K && p[r_pos] == p[r_pos + 1])
toadd -= (ll)L;
while(last_l >= 0)
{
toadd += p[last_l] * 2LL;
last_l -= K;
}
//cout << temp << " " << toadd << " " << p[r_pos] << " " << r_pos << "\n";
ans = min(ans, toadd);
// ans = min(ans, temp);
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... |