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>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pi;
typedef vector<pi> pii;
typedef tuple<int,int,int> tii;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define LSOne(s) ((s)&(-s))
ll INF=1e18+10;
int inf=1e9+10;
ll M=1e9+7;
pii a;
int n,k;
vector<vector<vector<ll>>> dp;
ll solve(int x,int y,int z,int p){//cerr<<x<<" "<<y<<" "<<z<<"\n";
if(dp[x][p][y]!=INF)return dp[x][p][y];
if(y==k-1)return dp[x][p][y]=max(0,z-a[x].F);
REP(i,0,n)if((y&(1<<i))==0)dp[x][p][y]=min(dp[x][p][y],solve(i,y|(1<<i),a[x].S,x)+max(0,z-a[x].F));
return dp[x][p][y];
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
n=s.size();
REP(i,0,n)a.PB({s[i],t[i]});
k=pow(2,n);
dp.resize(n,vector<vector<ll>>(n,vector<ll>(k+1,INF)));
ll ans=INF;
REP(i,0,n)ans=min(ans,solve(i,1<<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... |