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 F first
#define S second
#define pb push_back
#define INF 99999999999999
#define all(x) x.begin(),x.end()
typedef long long ll;
long long delivery(int N, int K, int L, int p[]) {
ll n=N;
vector<ll>v;
for(int i=0;i<n;i++)
v.pb(i);
ll ans=INF;
do
{
ll curr=min(p[v[0]],L-p[v[0]]);
ll count=K-1;
ll pos=v[0];
for(int i=0;i<n-1;i++)
{
if(count==0)
{
curr+=min(p[v[i]],L-p[v[i]]);
count=K;
pos=0;
}
count--;
if(abs(p[pos]-p[v[i+1]])>min(p[v[i+1]],L-p[v[i+1]]) + min(p[pos],L-p[pos]))
{
curr+=min(p[v[i+1]],L-p[v[i+1]]) + min(p[pos],L-p[pos]);
pos=v[i+1];
count=K-1;
}
else
curr+=abs(p[pos]-p[v[i+1]]);
}
curr+=min(p[pos] , L - p[pos]);
ans=min(ans,curr);
} while (next_permutation(all(v)));
return ans;
}
# | 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... |