joylintp

00532 - Dungeon Master

Aug 24th, 2021
1,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. //{
  5. //#pragma gcc optimize("Ofast,unroll-loops")
  6. //#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
  7. //#define int long long
  8. //#define double long double
  9. #define MP make_pair
  10. #define F first
  11. #define S second
  12. #define MOD 1000000007
  13. //}
  14.  
  15. signed main()
  16. {
  17.     ios_base::sync_with_stdio(false);
  18.     cin.tie(0);
  19.  
  20.     int L, R, C;
  21.     while (true)
  22.     {
  23.         cin >> L >> R >> C;
  24.         if (L == 0 && R == 0 && C == 0)
  25.             break;
  26.  
  27.         bool g[32][32][32] = {};
  28.         vector<int> S, E;
  29.         for (int i = 0; i < L; i++)
  30.             for (int j = 0; j < R; j++)
  31.             {
  32.                 string s;
  33.                 cin >> s;
  34.                 for (int k = 0; k < C; k++)
  35.                     if (s[k] != '#')
  36.                     {
  37.                         g[i + 1][j + 1][k + 1] = true;
  38.                         if (s[k] == 'S')
  39.                             S = {i + 1, j + 1, k + 1};
  40.                         if (s[k] == 'E')
  41.                             E = {i + 1, j + 1, k + 1};
  42.                     }
  43.             }
  44.  
  45.         bool vis[32][32][32] = {};
  46.         int dx[] = {-1, 1, 0, 0, 0, 0}, dy[] = {0, 0, -1, 1, 0, 0}, dz[] = {0, 0, 0, 0, -1, 1};
  47.         ///    dx  dy  dz
  48.         /// 0  -1   0   0
  49.         /// 1   1   0   0
  50.         /// 2   0  -1   0
  51.         /// 3   0   1   0
  52.         /// 4   0   0  -1
  53.         /// 5   0   0   1
  54.  
  55.         int dis[32][32][32] = {};
  56.         queue<pair<vector<int>, int>> q;
  57.         q.push(MP(S, 0)), vis[S[0]][S[1]][S[2]] = true;
  58.         while (!q.empty())
  59.         {
  60.             int x = q.front().first[0], y = q.front().first[1], z = q.front().first[2], d = q.front().second;
  61.             q.pop();
  62.  
  63.             for (int i = 0; i < 6; i++)
  64.             {
  65.                 int nx = x + dx[i], ny = y + dy[i], nz = z + dz[i];
  66.                 vector<int> np = {nx, ny, nz};
  67.                 if (!vis[nx][ny][nz] && g[nx][ny][nz])
  68.                     vis[nx][ny][nz] = true, dis[nx][ny][nz] = d + 1, q.push(MP(np, d + 1));
  69.             }
  70.         }
  71.  
  72.         if (!vis[E[0]][E[1]][E[2]])
  73.             cout << "Trapped!\n";
  74.         else
  75.             cout << "Escaped in " << dis[E[0]][E[1]][E[2]] << " minute(s).\n";
  76.     }
  77.  
  78.     return 0;
  79. }
  80.  
  81. //      *****  *****  *   *  *      *****  *   *  *****  *****
  82. //        *   *   *  *   *  *        *    **  *    *    *   *
  83. //       *   *   *  *****  *        *    * * *    *    *****
  84. //   *  *   *   *    *    *        *    *  **    *    *
  85. //  ****   *****    *    *****  *****  *   *    *    *
  86.  
  87. //     *   *   ***   *   *  **
  88. //    *   *  *   *  *   *  **
  89. //   * * *  *****  *****  **
  90. //  * * *  *   *  *   *
  91. //  * *   *   *  *   *  **
Advertisement
Add Comment
Please, Sign In to add comment