Advertisement
Guest User

Untitled

a guest
May 24th, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define rep(i, n) for(int i = 0; i < (n); i++)
  3. using namespace std;
  4.  
  5. const int INF = 1001001001;
  6.  
  7. int main() {
  8. const vector<int> d{1, 2, 5, 10};
  9. vector<vector<pair<int, int>>> to(1 << 5);
  10. rep(u, 1 << 5) {
  11. int light_place = u >> 4 & 1;
  12. vector<int> with_light;
  13. rep(i, 4) if ((u >> i & 1) == light_place) with_light.push_back(i);
  14. rep(x, with_light.size()) rep(y, with_light.size()) {
  15. if (x > y) continue;
  16. int i = with_light[x], j = with_light[y];
  17. int v = u ^ (1 << i | 1 << j | 1 << 4), cost = max(d[i], d[j]);
  18. to[u].emplace_back(v, cost);
  19. }
  20. }
  21. vector<int> dp(1 << 5, INF);
  22. priority_queue<pair<int, int>> q;
  23. dp[0] = 0;
  24. q.emplace(0, 0);
  25. while(!q.empty()) {
  26. int time = -q.top().first, u = q.top().second;
  27. q.pop();
  28. if (time != dp[u]) continue;
  29. for(auto vc: to[u]) {
  30. int v = vc.first, c = vc.second;
  31. int t = time + c;
  32. if (dp[v] <= t) continue;
  33. dp[v] = t;
  34. q.emplace(-t, v);
  35. }
  36. }
  37. cout << dp.back() << endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement