Submission #239263

#TimeUsernameProblemLanguageResultExecution timeMemory
239263urd05Roller Coaster Railroad (IOI16_railroad)C++14
34 / 100
97 ms30584 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...