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>
#define INF 1e18;
using namespace std;
int n;
vector<int> s, t;
long long memo[17][65537];
long long dp(int id, int mask){
//printf("%lld %lld\n",id,mask);
if (mask == (1<<n) - 1) return 0;
if (memo[id][mask] != -1) return memo[id][mask];
memo[id][mask] = INF;
for (int i = 0; i < n; i++){
if (!(mask&(1<<i))){
memo[id][mask] = min(memo[id][mask],dp(i,(mask|(1<<i)))+max(0,t[id]-s[i]));
}
}
return memo[id][mask];
}
long long plan_roller_coaster(vector<int> t1, vector<int> t2) {
n = (int) t1.size();
for (int i = 0; i < n; i++){
s.push_back(t1[i]);
t.push_back(t2[i]);
}
long long ans = INF;
if (n <= 16){
memset(memo,-1,sizeof(memo));
for (int i = 0; i < n; i++){
ans = min(ans,dp(i,1<<i));
}
}
else{
s.push_back(1000000001);
t.push_back(0);
sort(s.begin(),s.end(),greater<int>());
sort(t.begin(),t.end(),greater<int>());
for (int i = 0; i < n; i++){
if (s[i] < t[i]) return 1;
}
return 0;
}
return ans;
}
# | 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... |