Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define rep(i, n) for(int i = 0; i < (n); i++)
- using namespace std;
- const int INF = 1001001001;
- int main() {
- const vector<int> d{1, 2, 5, 10};
- vector<vector<pair<int, int>>> to(1 << 5);
- rep(u, 1 << 5) {
- int light_place = u >> 4 & 1;
- vector<int> with_light;
- rep(i, 4) if ((u >> i & 1) == light_place) with_light.push_back(i);
- rep(x, with_light.size()) rep(y, with_light.size()) {
- if (x > y) continue;
- int i = with_light[x], j = with_light[y];
- int v = u ^ (1 << i | 1 << j | 1 << 4), cost = max(d[i], d[j]);
- to[u].emplace_back(v, cost);
- }
- }
- vector<int> dp(1 << 5, INF);
- priority_queue<pair<int, int>> q;
- dp[0] = 0;
- q.emplace(0, 0);
- while(!q.empty()) {
- int time = -q.top().first, u = q.top().second;
- q.pop();
- if (time != dp[u]) continue;
- for(auto vc: to[u]) {
- int v = vc.first, c = vc.second;
- int t = time + c;
- if (dp[v] <= t) continue;
- dp[v] = t;
- q.emplace(-t, v);
- }
- }
- cout << dp.back() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement