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;
typedef long long ll;
const int MAXN = 15;
const ll inf = 1e18;
bool vis[MAXN];
ll cost(int n, int k, int l, int p[], vector<int> &v) {
int mn, mx;
int res = 0;
ll ans = 0;
for (int i = 0; i < n; i++) {
if (res == 0) {
mn = p[v[i]];
mx = p[v[i]];
}
else {
mn = min(mn, p[v[i]]);
mx = max(mx, p[v[i]]);
}
if (res == k-1 || i == n-1) {
ans += min(min(2*(l-mn), 2*mx), l);
}
res = (res+1)%k;
}
return ans;
}
ll make(int n, int k, int l, int p[], vector<int> &v) {
if (v.size() == n) return cost(n, k, l, p, v);
ll best = inf;
for (int i = 0; i < n; i++) {
if (vis[i]) continue;
v.push_back(i);
vis[i] = 1;
best = min(make(n, k, l, p, v), best);
vis[i] = 0;
v.pop_back();
}
return best;
}
ll delivery(int n, int k, int l, int p[]) {
vector<int> v;
return make(n, k, l, p, v);
}
Compilation message (stderr)
boxes.cpp: In function 'll make(int, int, int, int*, std::vector<int>&)':
boxes.cpp:35:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
35 | if (v.size() == n) return cost(n, k, l, p, v);
| ~~~~~~~~~^~~~
# | 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... |