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;
#define ll long long
ll delivery(int n, int k, int l, int a[])
{
if(n<=10)
{
ll ans = 100000000000;
vector<int> v; v.clear();
for(int i = 0; i < n; i++) v.push_back(a[i]);
do
{
ll sum = 0; int cur = 0;
for(int i = 0; i < n; i++)
{
sum+=min(abs(cur-v[i]), l-abs(cur-v[i])), cur = v[i];
if(i%k==k-1) sum+=min(cur, l-cur), cur = 0;
}
sum+=min(cur, l-cur), ans = min(ans, sum);
}while(next_permutation(v.begin(), v.end()));
return ans;
}
else if(k==1){
ll ans = 0;
for(int i = 0; i < n; i++) ans+=min((ll)a[i], (ll)l-a[i]);
return ans*2;
}
else if(k==n){
ll ans = min({l, a[n-1]*2, (l-a[0])*2});
for(int i = 0; i < n-1; i++)
ans = min(ans, (ll)(a[i]+(l-a[i+1]))*2ll),
ans = min(ans, (ll)(a[i-1]+(l-a[i]))*2ll);
return ans;
}
else {
ll ans = 0ll; int cur = 0;
int cnt = k, i = 0, j = 0;
for(i = 0; i < n; i++)
{
if(a[i]>l/2)break;
if(cnt==0) ans+=cur, cur = 0, cnt = k;
ans+=abs(cur-a[i]), cur = a[i];
if(cur==0) cnt = k+1; cnt--;
}
for(j = i; j < n; j++)
{
if(cnt==0)break;
ans+=abs(a[j]-cur), cur = a[j];
cnt--;
}
ans+=min(cur, l-cur);
cnt = k;
for(int i = n-1; i>=j; i--)
{
if(cnt==0) ans+=l-cur, cur = 0, cnt = k;
ans+=abs(cur-a[i]), cur = a[i];
if(cur==0) cnt = k+1; cnt--;
}
ans+=min(cur, l-cur);
return ans;
}
}
Compilation message (stderr)
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:44:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
44 | if(cur==0) cnt = k+1; cnt--;
| ^~
boxes.cpp:44:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
44 | if(cur==0) cnt = k+1; cnt--;
| ^~~
boxes.cpp:54:17: warning: declaration of 'i' shadows a previous local [-Wshadow]
54 | for(int i = n-1; i>=j; i--)
| ^
boxes.cpp:38:22: note: shadowed declaration is here
38 | int cnt = k, i = 0, j = 0;
| ^
boxes.cpp:58:13: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
58 | if(cur==0) cnt = k+1; cnt--;
| ^~
boxes.cpp:58:35: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
58 | if(cur==0) cnt = k+1; cnt--;
| ^~~
# | 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... |