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 "railroad.h"
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> ord;
vector<int> S, T;
long long ans = 1e18;
void bt(int i, long long sum);
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
S = s;
T = t;
n = s.size();
ord = vector<int> (n);
for(int i = 0; i < n; i++)
ord[i] = i;
bt(0, 0);
return ans;
}
void bt(int i, long long sum){
if(sum > ans) return;
if(i == n){
ans = sum;
return;
}
for(int j = i; j < n; j++){
swap(ord[i], ord[j]);
if(i != 0) sum += max(T[ord[i - 1]] - S[ord[i]], 0);
bt(i + 1, sum);
if(i != 0) sum -= max(T[ord[i - 1]] - S[ord[i]], 0);
swap(ord[i], ord[j]);
}
}
# | 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... |