From b9601e7499934bc7055789ae0a12205961402119 Mon Sep 17 00:00:00 2001 From: JinHyeok <101380919+YangJinHyeok@users.noreply.github.com> Date: Mon, 21 Jul 2025 22:11:33 +0900 Subject: [PATCH] =?UTF-8?q?[20250721]=20BAJ=20/=20=EA=B3=A8=EB=93=9C5=20/?= =?UTF-8?q?=20=EC=83=81=EB=B2=94=EB=B9=8C=EB=94=A9=20/=20=EC=96=91?= =?UTF-8?q?=EC=A7=84=ED=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...01\353\262\224\353\271\214\353\224\251.md" | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 "JinHyeok/202507/21 BAJ \354\203\201\353\262\224\353\271\214\353\224\251.md" diff --git "a/JinHyeok/202507/21 BAJ \354\203\201\353\262\224\353\271\214\353\224\251.md" "b/JinHyeok/202507/21 BAJ \354\203\201\353\262\224\353\271\214\353\224\251.md" new file mode 100644 index 0000000..91cd4c4 --- /dev/null +++ "b/JinHyeok/202507/21 BAJ \354\203\201\353\262\224\353\271\214\353\224\251.md" @@ -0,0 +1,84 @@ +``` +#include +#include +#include +using namespace std; + +int L, R, C; +char building[30][30][30]; +bool visited[30][30][30]; + +int dl[6] = {1, -1, 0, 0, 0, 0}; +int dr[6] = {0, 0, 1, -1, 0, 0}; +int dc[6] = {0, 0, 0, 0, 1, -1}; + +struct Node { + int l, r, c, dist; +}; + +int bfs(int sl, int sr, int sc) { + queue q; + q.push({sl, sr, sc, 0}); + visited[sl][sr][sc] = true; + + while (!q.empty()) { + Node cur = q.front(); + q.pop(); + + if (building[cur.l][cur.r][cur.c] == 'E') { + return cur.dist; + } + + for (int i = 0; i < 6; i++) { + int nl = cur.l + dl[i]; + int nr = cur.r + dr[i]; + int nc = cur.c + dc[i]; + + if (nl >= 0 && nl < L && nr >= 0 && nr < R && nc >= 0 && nc < C) { + if (!visited[nl][nr][nc] && building[nl][nr][nc] != '#') { + visited[nl][nr][nc] = true; + q.push({nl, nr, nc, cur.dist + 1}); + } + } + } + } + + return -1; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + while (true) { + cin >> L >> R >> C; + if (L == 0 && R == 0 && C == 0) break; + + int sl, sr, sc; + + for (int l = 0; l < L; l++) { + for (int r = 0; r < R; r++) { + for (int c = 0; c < C; c++) { + cin >> building[l][r][c]; + if (building[l][r][c] == 'S') { + sl = l; sr = r; sc = c; + } + visited[l][r][c] = false; + } + } + string dummy; + getline(cin, dummy); + } + + int result = bfs(sl, sr, sc); + if (result == -1) { + cout << "Trapped!\n"; + } else { + cout << "Escaped in " << result << " minute(s).\n"; + } + } + + return 0; +} + +```