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 <bits/stdc++.h>
#include "railroad.h"
using namespace std;
long long adj[20][20];
long long memo[20][66000];
long long tsp(int x,int bm){
if(memo[x][bm]!=-1)return memo[x][bm];
if(bm==0)return memo[x][bm]=0;
long long ans=1000000000000000010;
int bm2=bm;
while(bm2&(-bm2)){
int y=__builtin_ctz(bm2);
ans=min(ans,tsp(y,bm-(bm2&(-bm2)))+adj[x][y]);
bm2-=(bm2&(-bm2));
}
return memo[x][bm]=ans;
}
long long plan_roller_coaster(vector<int> s, vector<int> t) {
int n=(int)s.size();
if(n>16){
set<pair<int,int> > T;
for(int i=0;i<n;i++)T.insert(make_pair(t[i],i));
T.insert(make_pair(1,-1));
vector<pair<int,int> > S;
for(int i=0;i<n;i++)S.push_back(make_pair(s[i],i));
sort(S.begin(),S.end());
for(int i=0;i<n;i++){
set<pair<int,int> >::iterator it=T.upper_bound(make_pair(S[i].first,1000000010));
if(it==T.begin())return 1;
--it;
if(it->second==S[i].second){
if(it==T.begin())return 1;
--it;
}
T.erase(it);
}
return 0;
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)adj[i][j]=0;
else adj[i][j]=max(0,t[i]-s[j]);
}
}
memset(memo,-1,sizeof(memo));
long long ans=4000000000000000010;
for(int i=0;i<n;i++){
ans=min(ans,tsp(i,(1<<n)-1-(1<<i)));
}
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... |