-
Notifications
You must be signed in to change notification settings - Fork 0
/
6593.cpp
91 lines (77 loc) · 1.77 KB
/
6593.cpp
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// 테스트 케이스가 여러개 주어질 경우 꼭 초기화 하기!
#include<bits/stdc++.h>
using namespace std;
class Point {
public:
int floor;
int x;
int y;
Point(int floor, int y, int x) {
this->floor = floor;
this->y = y;
this->x = x;
}
};
int L, R, C;
int dx[6] = { 1, -1, 0, 0, 0, 0 };
int dy[6] = { 0, 0, 1, -1, 0, 0 };
int dz[6] = { 0, 0, 0, 0, 1, -1 };
vector<string> Map[30];
int depth[30][30][30];
void Reset() {
for (int i = 0; i < 30; i++) {
Map[i].clear();
}
}
string bfs(int floor, int y, int x) {
Point point(floor, y, x);
queue<Point> q;
q.push(point);
while (!q.empty()) {
Point cur = q.front();
q.pop();
if (Map[cur.floor][cur.y][cur.x] == 'E')
return "Escaped in " + to_string(depth[cur.floor][cur.y][cur.x]) + " minute(s).";
for (int i = 0; i < 6; i++) {
int nx = cur.x + dx[i];
int ny = cur.y + dy[i];
int nfloor = cur.floor + dz[i];
if (0 <= nx && nx < C && 0 <= ny && ny < R && 0 <= nfloor && nfloor < L
&& !depth[nfloor][ny][nx] && (Map[nfloor][ny][nx] == '.' || Map[nfloor][ny][nx] == 'E')) {
depth[nfloor][ny][nx] = depth[cur.floor][cur.y][cur.x] + 1;
q.push(Point(nfloor, ny, nx));
}
}
}
return "Trapped!";
}
int main() {
while (true) {
Reset();
memset(depth, 0, sizeof(depth));
cin >> L >> R >> C;
if (L == 0 && R == 0 && C == 0) break;
for (int i = 0; i < L; i++) {
for (int j = 0; j < R; j++) {
string s;
cin >> s;
Map[i].push_back(s);
}
}
bool escapeFlag = false;
for (int i = 0; i < L; i++) {
if (escapeFlag) break;
for (int j = 0; j < R; j++) {
if (escapeFlag) break;
for (int k = 0; k < C; k++) {
if (Map[i][j][k] == 'S') {
cout << bfs(i, j, k) << '\n';
escapeFlag = true;
break;
}
}
}
}
}
return 0;
}