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 <algorithm>
long long int memo[16][1<<16];
long long int recursion(int curr, int bitmask, std::vector<int> s, std::vector<int> t){
if(bitmask==0){
return 0;
}
int n = (int) s.size();
if(memo[curr][bitmask]!=-1){
return memo[curr][bitmask];
}
long long int ans=15000000000;
for(int i=0;i<n;i++){
if(bitmask&(1<<i)){
ans=std::min(ans, recursion(i, bitmask-(1<<i), s, t)+std::max(t[curr]-s[i], 0));
}
}
return memo[curr][bitmask]=ans;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
int n = (int) s.size();
if(n<=16){
for(int i=0;i<n;i++){
for(int j=0;j<(1<<n);j++){
memo[i][j]=-1;
}
}
long long int ans=15000000000;
for(int i=0;i<n;i++){
ans=std::min(ans, recursion(i, (1<<n)-1-(1<<i), s, t));
}
return ans;
}
std::pair<int, int> tsect[n];
for(int i=0;i<n;i++){
tsect[i]=std::make_pair(t[i], i);
}
std::sort(tsect, tsect+n);
return 0;
}
# | 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... |