Submission #743497

#TimeUsernameProblemLanguageResultExecution timeMemory
743497boris_mihovRoller Coaster Railroad (IOI16_railroad)C++17
34 / 100
91 ms10584 KiB
#include "railroad.h" #include <algorithm> #include <iostream> #include <numeric> #include <vector> typedef long long llong; const int MAXB = (1 << 16); const int MAXN = 16; int n; int s[MAXN]; int t[MAXN]; llong dp[MAXB][MAXN]; bool bl[MAXB][MAXN]; llong f(int mask, int last) { if (__builtin_popcount(mask) == n) { return 0; } if (bl[mask][last]) { return dp[mask][last]; } bl[mask][last] = true; dp[mask][last] = 1e18; for (int i = 0 ; i < n ; ++i) { if (mask & (1 << i)) { continue; } dp[mask][last] = std::min(dp[mask][last], f(mask | (1 << i), i) + std::max(0, t[last] - s[i])); } return dp[mask][last]; } llong plan_roller_coaster(std::vector<int> S, std::vector<int> T) { n = S.size(); for (int i = 0 ; i < n ; ++i) { s[i] = S[i]; t[i] = T[i]; } llong ans = 1e18; for (int i = 0 ; i < n ; ++i) { ans = std::min(ans, f(1 << i, i)); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...