Submission #597639

#TimeUsernameProblemLanguageResultExecution timeMemory
597639jophyyjhRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
45 ms13872 KiB
/** * I couldn't come up with anything except for subtasks 1-2, which can be killed * with the standard way of finding Hamiltonian paths. * * After that i headed to the editorial. The method is pretty shocking to me! * * Time Complexity: O(2^n * n^2) * Implementation 1 */ #include <bits/stdc++.h> #include "railroad.h" typedef long long ll; const ll INF = 0x3f3f3f3f3f3f; ll plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = s.size(); std::vector<std::vector<ll>> min_dist(1 << n, std::vector<ll>(n, INF)); for (int i = 0; i < n; i++) min_dist[1 << i][i] = 0; for (int set = 1; set < (1 << n); set++) { if ((set & (set - 1)) == 0) continue; for (int last = 0; last < n; last++) { if (((set >> last) & 1) == 0) continue; for (int last_two = 0; last_two < n; last_two++) { min_dist[set][last] = std::min( min_dist[set][last], min_dist[set ^ (1 << last)][last_two] + ll(std::max(t[last_two] - s[last], 0)) ); } } } ll min = INF; for (int i = 0; i < n; i++) min = std::min(min, min_dist[(1 << n) - 1][i]); return min; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...