Skip to content

Instantly share code, notes, and snippets.

@MapoCodingPark
Created May 11, 2020 02:36
백준 문제풀이
#include <bits/stdc++.h>
using namespace std;
// < z, x, y , time >
typedef tuple<int, int, int, int> tp;
int L, R, C;
int dx[] = { -1,1,0,0,0,0 };
int dy[] = { 0,0,-1,1,0,0 };
int dz[] = { 0,0,0,0,-1,1 };
// arr[z][x][y] : 층(z), 행(x), 열(y)
string arr[33][33];
bool visited[33][33][33];
void CanOut(int a, int b, int c) {
queue<tp> Q;
visited[a][b][c] = true;
Q.push(tp(a, b, c, 0));
while (!Q.empty()) {
tp now = Q.front();
Q.pop();
int z = get<0>(now);
int x = get<1>(now);
int y = get<2>(now);
int t = get<3>(now);
if (arr[z][x][y] == 'E') {
cout << "Escaped in " << t << " minute(s)." << '\n';
return;
}
for (int i = 0; i < 6; ++i) {
int nz = z + dz[i];
int nx = x + dx[i];
int ny = y + dy[i];
if (nz < 0 || nz >= L || nx < 0 || nx >= R || ny < 0 || ny >= C) continue;
if (visited[nz][nx][ny] || arr[nz][nx][ny] == '#') continue;
Q.push(tp(nz, nx, ny, t + 1));
visited[nz][nx][ny] = true;
}
}
cout << "Trapped!" << '\n';
}
int main() {ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL);
while (cin >> L >> R >> C) {
//초기화
for (int i = 0; i < 30; ++i)
for (int j = 0; j < 30; ++j)
arr[i][j].clear();
memset(visited, false, sizeof(visited));
for (int z = 0; z < L; ++z)
for (int x = 0; x < R; ++x)
cin >> arr[z][x];
for (int z = 0; z < L; ++z)
for (int x = 0; x < R; ++x)
for (int y = 0; y < C; ++y)
if (arr[z][x][y] == 'S')
CanOut(z, x, y);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment