Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(d) d.begin(), d.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef pair<int, int> pii;
- typedef long double ld;
- #define int long long
- const int inf = 1e13;
- signed main() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- struct Cube {
- int s1, s2, s3, s4, s5, s6;
- };
- int w, h, s1, s2, s4;
- cin >> h >> w >> s1 >> s2 >> s4;
- vector<vector<pii>> dist(w + 1, vector<pii>(h + 1, { inf,inf }));
- queue<pair<pii, pair<int, Cube>>>q;
- pair<int, Cube> start;
- dist[w - 1][1] = { s1,s1 };
- q.push({ {w - 1,1},{ s1, { s1, s2, 7 - s2, s4, 7 - s4, 7 - s1 } } });
- while (!q.empty()) {
- auto&& [x, y] = q.front().first;
- auto&& [d, p] = q.front().second;
- q.pop();
- if (y + 1 <= h &&
- d + p.s2 < dist[x][y + 1].second) {
- pair <ll, Cube> upd = {d + p.s2, { p.s2, p.s6, p.s1, p.s4, p.s5, p.s3 } };
- dist[x][y + 1].second = d + p.s2;
- q.push({ { x, y + 1}, upd });
- }
- if (x - 1 >= 0 && d + p.s4 < dist[x - 1][y].first) {
- pair <ll, Cube> upd = {d + p.s4,{ p.s4, p.s2, p.s3, p.s6, p.s1, p.s5 } };
- dist[x - 1][y].first = d + p.s4;
- q.push({ {x - 1,y},upd });
- }
- }
- cout << min(dist[0][h].first, dist[0][h].second);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement