Submission #591443

#TimeUsernameProblemLanguageResultExecution timeMemory
591443FatihSolakRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
48 ms10300 KiB
#include "railroad.h" #include <bits/stdc++.h> #define N 16 using namespace std; long long dp[(1<<N)][N]; long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int) s.size(); vector<pair<int,int>> v; for(int i = 0;i<n;i++){ v.push_back({s[i]-t[i],i}); } long long ans = 0; int last = 1; for(int i = 0;i<n;i++){ ans += max(0,last - s[v[i].second]); last = t[v[i].second]; } for(int i = 0;i<(1<<n);i++){ for(int j = 0;j<n;j++){ dp[i][j] = 2e18; } } for(int i = 0;i<n;i++){ dp[(1<<i)][i] = 0; } for(int mask = 1;mask <(1<<n);mask++){ for(int i = 0;i<n;i++){ if(!(mask & (1<<i)))continue; for(int j = 0;j<n;j++){ if(mask & (1<<j))continue; dp[mask + (1<<j)][j] = min(dp[mask + (1<<j)][j],dp[mask][i] + max(0,t[i] - s[j])); } //cout << mask << " " << i << " " << dp[mask][i] << endl; } } long long ret = 2e18; for(int i = 0;i<n;i++){ ret = min(ret,dp[(1<<n)-1][i]); } if(ret == ans){ for(int i = 0;i<1e9;i++){ ans += s[i%n]; } } 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...