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 <cstdio>
#include <cassert>
#include<bits/stdc++.h>
using namespace std;
long long n,dp[(1<<17)+555][20];
vector<int>en,ex;
long long f(int mask,int last)
{
if(mask==(1<<n)-1)return 0;
if(dp[mask][last]!=-1)return dp[mask][last];
long long ans=1e18;
for(int i=0;i<n;i++)
{
if((mask&(1<<i))==0)
{
long long dis=max(0,ex[last]-en[i]);
ans=min(ans,dis+f((mask|(1<<i)),i));
}
}
return dp[mask][last]=ans;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t)
{
memset(dp,-1,sizeof dp);
n=s.size();
en=s;
ex=t;
en.insert(en.begin(),0);
ex.insert(ex.begin(),1);
n++;
long long mn=1e18;
return f(1,0);
}
Compilation message (stderr)
railroad.cpp: In function 'long long int plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:32:15: warning: unused variable 'mn' [-Wunused-variable]
long long mn=1e18;
^~
# | 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... |