Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.29 KB | None | 0 0
  1. /*
  2.     $$$$$$$\                      $$\           $$$$$$$\
  3.     $$  __$$\                     \__|          $$  __$$\
  4.     $$ |  $$ | $$$$$$\   $$$$$$\  $$\  $$$$$$$\ $$ |  $$ | $$$$$$\   $$$$$$\   $$$$$$$\ $$$$$$\
  5.     $$$$$$$\ |$$  __$$\ $$  __$$\ $$ |$$  _____|$$$$$$$\ | \____$$\ $$  __$$\ $$  _____|\____$$\
  6.     $$  __$$\ $$ /  $$ |$$ |  \__|$$ |\$$$$$$\  $$  __$$\  $$$$$$$ |$$ |  \__|$$ /      $$$$$$$ |
  7.     $$ |  $$ |$$ |  $$ |$$ |      $$ | \____$$\ $$ |  $$ |$$  __$$ |$$ |      $$ |     $$  __$$ |
  8.     $$$$$$$  |\$$$$$$  |$$ |      $$ |$$$$$$$  |$$$$$$$  |\$$$$$$$ |$$ |      \$$$$$$$\\$$$$$$$ |
  9.     \_______/  \______/ \__|      \__|\_______/ \_______/  \_______|\__|       \_______|\_______|
  10. */
  11. #include <bits/stdc++.h>
  12.  
  13. using namespace std;
  14.  
  15. #define PB push_back
  16. #define MP make_pair
  17. #define INS insert
  18. #define LB lower_bound
  19. #define UB upper_bound
  20. #define pii pair <int,int>
  21. #define pll pair <long long, long long>
  22. #define si pair<string, int>
  23. #define is pair<int, string>
  24. #define X first
  25. #define Y second
  26. #define _ << " " <<
  27. #define sz(x) (int)x.size()
  28. #define all(a) (a).begin(),(a).end()
  29. #define FOR(i, a, b) for (int i = (a); i < (b); ++i)
  30. #define FORD(i, a, b) for (int i = (a); i > (b); --i)
  31. #define FORR(i, l, r) for (int i = (l); i <= (r); ++i)
  32. #define FORP(i, a, b) for ((i) = (a); (i) < (b); ++i)
  33. #define FORA(i, x) for (auto &i : x)
  34. #define REP(i, n) FOR(i, 0, n)
  35. #define BITS(x) __builtin_popcount(x)
  36. #define MSET memset
  37. #define MCPY memcpy
  38. #define SQ(a) (a) * (a)
  39.  
  40. typedef long long ll;
  41. typedef long double ld;
  42. typedef vector <int> vi;
  43. typedef vector <pii> vpi;
  44. typedef vector <ll> vll;
  45. typedef vector <pll> vpl;
  46. typedef vector <double> vd;
  47. typedef vector <ld> vld;
  48. typedef vector<si> vsi;
  49. typedef vector<is> vis;
  50. typedef vector<string> vs;
  51. //((float) t)/CLOCKS_PER_SEC
  52.  
  53. const int MOD = 20183;
  54. const int CX = 16807;
  55. const int CY = 48271;
  56. const int PI = acos(-1);
  57. const int LOG = 32;
  58. const int INF = 1e9 + 10;
  59. const ll INFL = 1e18 + 10;
  60. const int ABC = 30;
  61. const int dx[] = {-1, 1, 0, 0};
  62. const int dy[] = {0, 0, -1, 1};
  63. const int dox[] = {-1, 1, 0, 0, -1, -1, 1, 1};
  64. const int doy[] = {0, 0, -1, 1, -1, 1, -1, 1};
  65.  
  66. inline int sum(int a, int b){
  67.   if (a + b >= MOD)
  68.     return a + b - MOD;
  69.   if (a + b < 0)
  70.     return a + b + MOD;
  71.   return a + b;
  72. }
  73.  
  74. inline void add(ll &a, int b){
  75.   a = sum(a, b);
  76. }
  77.  
  78. inline ll mul(int a, int b){
  79.   return ((ll)a * (ll)b) % MOD;
  80. }
  81.  
  82. inline int sub(int a, int b){
  83.     return (a - b + MOD) % MOD;
  84. }
  85.  
  86. inline int pot(ll pot, int n){
  87.     ll ret = 1;
  88.     while (n){
  89.         if (n & 1)
  90.             ret = (ret * pot) % MOD;
  91.         pot = (pot * pot) % MOD;
  92.         n >>= 1;
  93.     }
  94.     return ret;
  95. }
  96.  
  97. inline int divide(int a, int b){
  98.     return mul(a, pot(b, MOD - 2));
  99. }
  100.  
  101. ll lcm(ll a, ll b){
  102.     return abs(a * b) / __gcd(a, b);
  103. }
  104.  
  105. inline double ccw(pii A, pii B, pii C){
  106.     return (A.X * B.Y) - (A.Y * B.X) + (B.X * C.Y) - (B.Y * C.X) + (C.X * A.Y) - (C.Y * A.X);
  107. }
  108.  
  109. inline int CCW(pii A, pii B, pii C){
  110.     double val = ccw(A, B, C);
  111.     double eps = max(max(abs(A.X), abs(A.Y)), max(max(abs(B.X), abs(B.Y)), max(abs(C.X), abs(C.Y)))) / 1e9;
  112.     if (val <= -eps)
  113.         return -1;
  114.     if (val >= eps)
  115.         return 1;
  116.     return 0;
  117. }
  118.  
  119. void to_upper(string &x){
  120.     REP(i, sz(x))
  121.         x[i] = toupper(x[i]);
  122. }
  123.  
  124. void to_lower(string &x){
  125.     REP(i, sz(x))
  126.         x[i] = tolower(x[i]);
  127. }
  128.  
  129. string its(ll x){
  130.     if (x == 0)
  131.         return "0";
  132.     string ret = "";
  133.     while (x > 0){
  134.         ret += (x % 10) + '0';
  135.         x /= 10;
  136.     }
  137.     reverse(all(ret));
  138.     return ret;
  139. }
  140.  
  141. ll sti(string s){
  142.     ll ret = 0;
  143.     REP(i, sz(s)){
  144.         ret *= 10;
  145.         ret += (s[i] - '0');
  146.     }
  147.     return ret;
  148. }
  149.  
  150. const int N = 1001;
  151.  
  152. ll g[N][N], sol[N][N][3], d = 5913, x = 701, y = 8;
  153. char mat[N][N], e[3] = {'.', '=', '|'};
  154. bool bio[N][N][3];
  155.  
  156. struct state{
  157.     int x, y, g, d;
  158.     state(int _x, int _y, int _g, int _d){
  159.         x = _x, y = _y, g = _g, d = _d;
  160.     }
  161. };
  162.  
  163. class CMP{
  164.     public:
  165.         bool operator ()(state &a, state &b){
  166.             return a.d > b.d;
  167.         }
  168. };
  169.  
  170. // 0 - climbing gear
  171. // 1 - torch
  172. // 2 - neither
  173. // rocky - 0 or 1
  174. // wet - 0 or 2
  175. // narrow 1 or 2
  176.  
  177. void part1(){
  178.     ll sol = 0;
  179.     REP(i, x + 1){
  180.         REP(j, y + 1){
  181.             sol += g[i][j];
  182.         }
  183.     }
  184.     cout << sol << '\n';
  185. }
  186.  
  187. bool ok(int x, int y){
  188.     return x > -1 && y > -1 && x < N && y < N;
  189. }
  190.  
  191. ll dijkstra(){
  192.     priority_queue <state, vector <state>, CMP> q;
  193.     q.push(state(0, 0, 1, 0));
  194.     while (!q.empty()){
  195.         state s = q.top();
  196.         q.pop();
  197.         if (bio[s.x][s.y][s.g])
  198.             continue;
  199.         if (s.x == x && s.y == y && s.g == 1)
  200.             return s.d;
  201.         bio[s.x][s.y][s.g]++;
  202.         REP(i, 4){
  203.             int nx = s.x + dx[i],
  204.                 ny = s.y + dy[i];
  205.             if (ok(nx, ny) && !bio[nx][ny][s.g] && g[nx][ny] != s.g)
  206.                 q.push(state(nx, ny, s.g, s.d + 1));
  207.         }
  208.         REP(i, 3){
  209.             int nx = s.x,
  210.                 ny = s.y;
  211.             if (ok(nx, ny) && !bio[nx][ny][i] && g[nx][ny] != i)
  212.                 q.push(state(nx, ny, i, s.d + 7));
  213.         }
  214.     }
  215. }
  216.  
  217. void part2(){
  218.     cout << dijkstra() << '\n';
  219. }
  220.  
  221. int main () {
  222.     ios_base::sync_with_stdio(false);
  223.     cin.tie(0);
  224.     cout.tie(0);
  225.  
  226.     REP(i, N){
  227.         REP(j, N){
  228.             if (i == 0){
  229.                 if (j == 0)
  230.                     g[i][j] = 0;
  231.                 else
  232.                     g[i][j] = mul(j, CX);
  233.             } else {
  234.                 if (j == 0)
  235.                     g[i][j] = mul(i, CY);
  236.                 else
  237.                     g[i][j] = mul(g[i - 1][j], g[i][j - 1]);
  238.             }
  239.             add(g[i][j], d);
  240.         }
  241.     }
  242.     REP(i, N){
  243.         REP(j, N){
  244.             mat[i][j] = e[g[i][j] % 3];
  245.             g[i][j] %= 3;
  246.         }
  247.     }
  248.     g[x][y] = 0;
  249.     part2();
  250.  
  251.     return 0;
  252. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement