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>
using namespace std;
long long dp[16][65536]; //recent,visited.
int need[200000];
int sp[200000];
int n;
long long ans(int rec,int bit) {
if (dp[rec][bit]!=-1) {
return dp[rec][bit];
}
if (bit==(1<<rec)) {
dp[rec][bit]=0;
return dp[rec][bit];
}
long long ret=1e15;
for(int i=0;i<n;i++) {
if (i!=rec&&((bit>>i)&1)) {
ret=min(ret,ans(i,bit-(1<<rec))+max(0,sp[i]-need[rec]));
}
}
dp[rec][bit]=ret;
return ret;
}
long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
n = (int) s.size();
for(int i=0;i<n;i++) {
need[i]=s[i];
sp[i]=t[i];
}
memset(dp,-1,sizeof(dp));
long long ret=1e15;
for(int i=0;i<n;i++) {
ret=min(ret,ans(i,(1<<n)-1));
}
return 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... |