-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path532.cpp
More file actions
70 lines (68 loc) · 2.03 KB
/
532.cpp
File metadata and controls
70 lines (68 loc) · 2.03 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
#define inf 10000000
#define mem(a, b) memset(a, b, sizeof(a))
#define NN 30
const int dx[] = {0, -1, 0, 1, 0, 0};
const int dy[] = {-1, 0, 1, 0, 0, 0};
const int dz[] = {0, 0, 0, 0, 1, -1};
char a[NN + 7][NN + 7][NN + 7];
int dist[NN + 7][NN + 7][NN + 7];
queue<int> X, Y, Z;
int R, C, L;
int bfs(int si, int sj, int sz) {
X = Y = Z = queue<int>();
X.push(si), Y.push(sj), Z.push(sz);
mem(dist, -1);
dist[sz][si][sj] = 0;
while (!X.empty()) {
int x = X.front();
int y = Y.front();
int z = Z.front();
X.pop(), Y.pop(), Z.pop();
for (int r = 0; r < 6; r++) {
int i = x + dx[r];
int j = y + dy[r];
int k = z + dz[r];
if (i < 0 || j < 0 || k < 0 || i >= R || j >= C || k >= L) continue;
if (a[k][i][j] != '#' && dist[k][i][j] == -1) {
X.push(i), Y.push(j), Z.push(k);
dist[k][i][j] = dist[z][x][y] + 1;
if (a[k][i][j] == 'E') return dist[k][i][j];
}
}
}
return -1;
}
int main() {
// freopen("C:\\Users\\Maruf Tuhin\\Desktop\\in.txt","r",stdin);
// ios_base::sync_with_stdio(false);
int i, j, k, l, n, r, c, si, sj, sk;
int tc, t = 1;
// cin>>tc;
while (~scanf("%d%d%d", &L, &R, &C)) {
if (L == 0 && R == 0 && C == 0) return 0;
k = 0;
for (k = 0; k < L; k++)
for (i = 0; i < R; i++) {
scanf("%s", &a[k][i]);
for (j = 0; j < C; j++)
if (a[k][i][j] == 'S') si = i, sj = j, sk = k;
}
n = bfs(si, sj, sk);
if (n == -1)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n", n);
}
return 0;
}