This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// time_limit/hazem_qn-factorial.cpp
#include "bits/stdc++.h"
#include "nile.h"
using namespace std;
const long long INF = 1e14;
vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
int n = W.size();
int q = E.size();
auto solve = [&](int d){
long long tot = INF;
vector <int> p(n);
iota(p.begin() ,p.end() ,0);
do{
long long cur = (n % 2) * A[p.back()];
for(int i = 0; i + 1 < n; i += 2){
int j = p[i], k = p[i + 1];
cur += (abs(W[j] - W[k]) <= d? B[j] + B[k] : A[j] + A[k]);
}
tot = min(tot, cur);
} while(next_permutation(p.begin() ,p.end()));
return tot;
};
vector<long long> R(q);
for(int i = 0; i < q; i++)
R[i] = solve(E[i]);
return R;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |