Advertisement
ivnikkk

Untitled

Jun 21st, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
  3. #include "bits/stdc++.h"
  4. using namespace std;
  5. #define all(d) d.begin(), d.end()
  6. typedef long long ll;
  7. typedef pair<ll, ll> pll;
  8. typedef pair<int, int> pii;
  9. typedef long double ld;
  10. #define int long long
  11. const int inf = 1e13;
  12. signed main() {
  13. #ifdef _DEBUG
  14.     freopen("input.txt", "r", stdin);
  15.     freopen("output.txt", "w", stdout);
  16. #endif
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(nullptr);
  19.     cout.tie(nullptr);
  20.     struct Cube {
  21.         int s1, s2, s3, s4, s5, s6;
  22.     };
  23.     int w, h, s1, s2, s4;
  24.     cin >> h >> w >> s1 >> s2 >> s4;
  25.     vector<vector<pii>> dist(w + 1, vector<pii>(h + 1, { inf,inf }));
  26.     queue<pair<pii, pair<int, Cube>>>q;
  27.     pair<int, Cube> start;
  28.     dist[w - 1][1] = { s1,s1 };
  29.     q.push({ {w - 1,1},{ s1, { s1, s2, 7 - s2, s4, 7 - s4, 7 - s1 } } });
  30.     while (!q.empty()) {
  31.         auto&& [x, y] = q.front().first;
  32.         auto&& [d, p] = q.front().second;
  33.         q.pop();
  34.         if (y + 1 <= h &&
  35.             d + p.s2 < dist[x][y + 1].second) {
  36.             pair <ll, Cube> upd = {d + p.s2, { p.s2, p.s6, p.s1, p.s4, p.s5, p.s3 } };
  37.             dist[x][y + 1].second = d + p.s2;
  38.             q.push({ { x, y + 1}, upd });
  39.         }
  40.         if (x - 1 >= 0 && d + p.s4 < dist[x - 1][y].first) {
  41.             pair <ll, Cube> upd = {d + p.s4,{ p.s4, p.s2, p.s3, p.s6, p.s1, p.s5 } };
  42.             dist[x - 1][y].first = d + p.s4;
  43.             q.push({ {x - 1,y},upd });
  44.         }
  45.     }
  46.     cout << min(dist[0][h].first, dist[0][h].second);
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement