Advertisement
skimono

Untitled

Apr 29th, 2022
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.15 KB | None | 0 0
  1. /*
  2. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  3. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  4. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  5. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠿⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  6. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⢛⣉⣥⣤⣶⣶⣶⣶⣶⣶⣤⣬⣉⡛⠿⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  7. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣩⣴⣾⣿⣿⣿⣿⣿⣿⡿⠟⠛⠛⠻⢿⣿⣿⣷⣦⣍⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  8. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⣡⣾⣿⣿⣿⣿⣿⣿⣿⡿⢃⣴⣾⣿⠋⣁⣀⠙⣿⣿⣿⣿⣷⣌⠹⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  9. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⢡⣾⣿⣿⣿⣿⣿⣿⣿⣿⡿⠇⣼⣿⣿⣿⣷⠸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣌⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  10. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⣰⣿⣿⣿⣿⣿⣿⣿⡿⡋⢑⣤⣤⡙⢿⣿⡿⠟⣠⣈⠝⠻⣿⣿⣿⣿⣿⣿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿
  11. ⣿⣿⣿⣿⣿⣿⣿⣿⡟⢰⣿⣿⣿⣿⣿⣿⡿⡃⣠⣾⣿⣿⣿⣷⣶⣶⣶⣾⣿⣿⣷⣄⢈⢿⣿⣿⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿
  12. ⣿⣿⣿⣿⣿⣿⣿⣿⠃⣿⣿⣿⣿⣿⣿⡟⠀⣴⣿⣿⣿⣿⡿⠟⠛⠛⠻⢿⣿⣿⣿⣿⣧⠉⢻⣿⣿⣿⣿⣿⣿⡈⣿⣿⣿⣿⣿⣿⣿⣿
  13. ⣿⣿⣿⣿⣿⣿⣿⡿⢸⣿⣿⣿⣿⣿⣿⢣⢰⣿⣿⣿⣿⠏⣠⣾⣿⣿⣷⣦⠹⣿⣿⣿⣿⡇⡌⣿⣿⣿⣿⣿⣿⡇⢻⣿⣿⣿⣿⣿⣿⣿
  14. ⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⢿⣿⣿⠸⢸⣿⣿⣿⣿⠀⣿⣿⣿⣿⣿⣿⠄⣿⣿⣿⣿⡇⠀⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿
  15. ⣿⣿⣿⣿⣿⣿⣿⣿⢸⣿⣿⡇⡀⣿⠋⣤⣤⣤⡙⢿⣿⣆⠹⣿⣿⣿⣿⠟⣰⣿⣿⠟⠛⠃⠢⣿⣿⣿⣿⣿⣿⡇⣾⣿⣿⣿⣿⣿⣿⣿
  16. ⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⣿⡇⢳⣤⣼⣿⣿⣿⣿⢘⣿⣿⣷⣦⣬⣤⣴⣾⣿⡿⢡⣾⣿⣿⣷⡌⢻⣿⣿⣿⣿⢁⣿⣿⣿⣿⣿⣿⣿⣿
  17. ⣿⣿⣿⣿⣿⣿⣿⣿⢧⠸⣿⣿⣄⠻⠿⣿⣿⠿⠋⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠸⣿⣿⣿⣿⣿⠘⣿⣿⣿⠏⣼⣿⣿⣿⣿⣿⣿⣿⣿
  18. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⠹⣿⣿⣿⣶⣶⣶⣶⣦⣄⡉⣛⠿⠿⠿⠿⠿⠿⠛⠉⣂⣤⣉⡉⢹⠟⣰⣿⣿⠏⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿
  19. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣧⡘⢿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣭⣥⣤⣤⣴⣶⣿⣿⡿⠋⢀⣡⣴⣿⡿⢋⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  20. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣆⡙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  21. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣉⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⣋⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  22. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣬⣉⡛⠻⠿⠿⠿⠿⠿⠿⠟⢛⣋⣥⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  23. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣶⣶⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  24. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  25. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  26. ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
  27. */
  28.  
  29. #pragma GCC optimize("Ofast")
  30. #pragma GCC target("avx2")
  31.  
  32. #define _CRT_SECURE_NO_WARNINGS
  33.  
  34. #include <iostream>
  35. #include <vector>
  36. #include <string>
  37. #include <algorithm>
  38. #include <cmath>
  39. #include <stack>
  40. #include <iomanip>
  41. #include <fstream>
  42. #include <string>
  43. #include <set>
  44. #include <deque>
  45. #include <queue>
  46. #include <map>
  47. #include <bitset>
  48. #include <random>
  49. #include <list>
  50. #include <unordered_map>
  51. #include <unordered_set>
  52. #include <cassert>
  53.  
  54. using namespace std;
  55.  
  56. typedef long long ll;
  57. typedef unsigned long long ull;
  58. typedef long double ld;
  59. typedef string str;
  60. //typedef __int128 ultraint;
  61. #define endl "\n"
  62. #define sqrt sqrtl
  63. //#define pow fast_pow
  64.  
  65. const ll inf = (ll)1e18 + 7;
  66. ld eps = 1e-6;
  67. ld Pi = 3.14159265358979323846;
  68.  
  69. struct kub {
  70.     ll verh, left, right, front1, back1, back2;
  71. };
  72.  
  73. signed main() {
  74. #ifdef _DEBUG
  75.     freopen("in.txt", "r", stdin);
  76.     freopen("out.txt", "w", stdout);
  77. #endif
  78.     //freopen("wall.in", "r", stdin);
  79.     //freopen("wall.out", "w", stdout);
  80.     ios_base::sync_with_stdio(0);
  81.     cin.tie(NULL);
  82.     cout.tie(NULL);
  83.     ll t = 1;
  84.     //cin >> t
  85.     while (t--) {
  86.         ll w, h, i, j, verh, left, front1;
  87.         cin >> h >> w;
  88.         vector < vector <pair <ll, ll> > > u(w + 1, vector <pair <ll, ll> >(h + 1, { inf,inf }));
  89.         queue <pair <pair <ll, ll>, pair <ll, kub> > >q;
  90.         cin >> verh >> left >> front1;
  91.         pair <ll, kub> start;
  92.         start.second = { verh,left,7 - left,front1,7 - front1,7 - verh };
  93.         start.first = start.second.verh;
  94.         u[w - 1][1] = { start.first,start.first };
  95.         q.push({ {w - 1,1},start });
  96.         while (!q.empty()) {
  97.             pair <ll, ll> loc = q.front().first;
  98.             pair <ll, kub> val = q.front().second;
  99.             q.pop();
  100.             if (loc.first - 1 >= 0 && val.first + val.second.front1 < u[loc.first - 1][loc.second] .first) {
  101.                 pair <ll, kub> sup;
  102.                 sup.first = val.first + val.second.front1;
  103.                 u[loc.first - 1][loc.second].first = sup.first;
  104.                 sup.second.verh = val.second.front1;
  105.                 sup.second.left = val.second.left;
  106.                 sup.second.right = val.second.right;
  107.                 sup.second.front1 = val.second.back2;
  108.                 sup.second.back1 = val.second.verh;
  109.                 sup.second.back2 = val.second.back1;
  110.                 q.push({ {loc.first - 1,loc.second},sup });
  111.             }
  112.             if (loc.second + 1 <= h && val.first + val.second.left < u[loc.first][loc.second + 1].second) {
  113.                 pair <ll, kub> sup;
  114.                 sup.first = val.first + val.second.left;
  115.                 u[loc.first][loc.second + 1].second = sup.first;
  116.                 sup.second.verh =val.second.left;
  117.                 sup.second.left = val.second.back2;
  118.                 sup.second.right = val.second.verh;
  119.                 sup.second.front1 = val.second.front1;
  120.                 sup.second.back1 = val.second.back1;
  121.                 sup.second.back2 = val.second.right;
  122.                 q.push({ {loc.first,loc.second + 1},sup });
  123.             }
  124.         }
  125.         cout << min(u[0][h].first, u[0][h].second) << endl;
  126.     }
  127. }
  128. //痛みを受け入れる。 痛みを知っています。 痛みを感じる。 痛みを参照してください。 真の痛みを知らなければ、真の世界を理解することは不可能です。 今、あなたは痛みを知るでしょう。 神の罰!
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement