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"
#define F first
#define S second
#define P push
#define pb push_back
#define MEM(dp,i) memset(dp,i,sizeof(dp))
#define W while
#define R return
#define C continue
#define SI size()
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define SF(x) scanf("%I64d",&x)
#define SF2(x,y) scanf("%I64d%I64d",&x,&y)
#define SF3(x,y,z) scanf("%I64d%I64d%I64d",&x,&y,&z)
#define SF4(x,y,z,o) scanf("%I64d%I64d%I64d%I64d",&x,&y,&z,&o)
#define all(v) v.begin(),v.end()
using namespace std;
const long long INF = 1e15;
const int MX=1000005;
vector<int> s,e;
int n;
ll dp[17][(1<<16)+6];
ll DP(int x,int mask){
if(mask==(1<<n)-1)R 0;
ll &ret=dp[x][mask];
if(ret!=-1)R ret;
ret=INF;
for(int i=0;i<n;i++){
if((1<<i)&mask)C;
if(e[x]>s[i]){
ret=min(ret,DP(i,mask+(1<<i))+e[x]-s[i]);
}
else{
ret=min(ret,DP(i,mask+(1<<i)));
}
}
R ret;
}
long long plan_roller_coaster(vector<int> s_, vector<int> t) {
n=s_.SI;
MEM(dp,-1);
s=s_,e=t;
ll ret=INF;
for(int i=0;i<n;i++){
ret=min(ret,DP(i,(1<<i)));
}
R ret;
}
# | 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... |