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 "grader.cpp"
#include <cstring>
using namespace std;
const long long inf = 1e18 + 5;
int n;
vector <int> s, t;
long long memo[(1<<17)+5][20];
long long rec(int used, int usedCnt, int last)
{
if(usedCnt==n) return 0;
if(memo[used][last]!=-1) return memo[used][last];
long long answer = inf;
for(int nxt = 0;nxt<n;nxt++)
{
if(((used>>nxt)&1)==1) continue;
answer = min(answer, rec(used+(1<<nxt), usedCnt+1, nxt) + max(0, t[last]-s[nxt]));
}
memo[used][last] = answer;
return answer;
}
long long plan_roller_coaster(vector<int> _s, vector<int> _t)
{
s = _s;
t = _t;
n = s.size();
memset(memo, -1, sizeof(memo));
long long answer = inf;
for(int first = 0;first<n;first++) answer = min(answer, rec((1<<first), 1, first));
return answer;
}
# | 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... |