Submission #593720

#TimeUsernameProblemLanguageResultExecution timeMemory
593720Valaki2Roller Coaster Railroad (IOI16_railroad)C++14
34 / 100
236 ms524288 KiB
#include "railroad.h" #include <bits/stdc++.h> using namespace std; #define int long long const int inf = 1e16 + 42; int n; vector<int> in; vector<int> out; vector<vector<int> > step; vector<vector<int> > dp; int solve() { step.assign(n, vector<int> (n, 0)); for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { if(i != j) { step[i][j] = max(out[i] - in[j], 0ll); } } } dp.assign((1 << n), vector<int> (n, inf)); for(int mask = 1; mask < (1 << n); mask++) { for(int cur = 0; cur < n; cur++) { if(!(mask & (1 << cur))) { continue; } if(__builtin_popcount(mask) == 1) { dp[mask][cur] = 0; continue; } int prev_mask = mask - (1 << cur); for(int nei = 0; nei < n; nei++) { if(!(prev_mask & (1 << nei))) { continue; } dp[mask][cur] = min(dp[mask][cur], dp[prev_mask][nei] + step[nei][cur]); } } } int ans = inf; for(int i = 0; i < n; i++) { ans = min(ans, dp[(1 << n) - 1][i]); } return ans; } int plan_roller_coaster(vector<signed> s, vector<signed> t) { n = (int) s.size(); in.assign(n, 0); out.assign(n, 0); for(int i = 0; i < n; i++) { in[i] = s[i]; out[i] = t[i]; } return solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...