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"
//#include "grader.cpp"
using namespace std ;
const int MAX = 17 ;
vector<int>a , b ;
long long dp[MAX][(1 << MAX)] ;
int n ;
long long solve(int idx , int mask)
{
if(mask == (1 << n) - 1)
return 0 ;
long long &ret = dp[idx][mask] ;
if(ret != -1)
return ret ;
ret = 1e12 ;
for(int i = 0 ; i < n ; ++i)
{
if((mask & (1 << i)))
continue ;
ret = min(ret , solve(i , mask | (1 << i)) + max(0ll , b[idx]*1ll - a[i]*1ll)) ;
}
return ret ;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
memset(dp , -1 , sizeof(dp)) ;
n = (int) s.size();
a = s , b = t ;
long long ans = 1e18 ;
for(int i = 0 ; i < n ; ++i)
ans = min(ans , solve(i , 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... |