Submission #61221

#TimeUsernameProblemLanguageResultExecution timeMemory
61221KubalionzzaleRoller Coaster Railroad (IOI16_railroad)C++14
34 / 100
143 ms42436 KiB
#include "railroad.h" #include <iostream> #include <algorithm> long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) { int n = (int) s.size(); long long int dp[100010][20] = { 0 }; dp[0][0] = 0; int val = 1 << n; for (int x = 1; x < val; ++x) { for (int j = 0; j < n; ++j) { dp[x][j] = 1e15; } } for (int x = 1; x < val; ++x) { int bitNr = __builtin_popcount(x); if (bitNr == 1) { for (int j = 0; j < n; ++j) { if (x & (1 << j)) { dp[x][j] = 0; break; } } } else { for (int j = 0; j < n; ++j) { if (x & (1 << j)) { int newNr = x ^ (1 << j); for (int k = 0; k < n; ++k) { if (newNr & (1 << k)) { dp[x][j] = std::min(dp[x][j], dp[newNr][k] + std::max(0, t[k] - s[j])); } } } } } } /* for (int x = 1; x < val; ++x) { for (int j = 0; j < n; ++j) { std::cout << x << " " << j << " " << dp[x][j] << "\n"; } } */ --val; long long int ans = 1e15; for (int i = 0; i < n; ++i) { ans = std::min(ans, dp[val][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...