From c8d46ab31bc58befee8983b6a0f78ee83705066f Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Wed, 13 Aug 2025 10:12:10 +0900 Subject: [PATCH] =?UTF-8?q?[20250813]=20BOJ=20/=20G5=20/=20=EC=83=81?= =?UTF-8?q?=EB=B2=94=20=EB=B9=8C=EB=94=A9=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\353\262\224 \353\271\214\353\224\251.md" | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 "suyeun84/202508/13 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" diff --git "a/suyeun84/202508/13 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" "b/suyeun84/202508/13 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" new file mode 100644 index 00000000..28625f30 --- /dev/null +++ "b/suyeun84/202508/13 BOJ G5 \354\203\201\353\262\224 \353\271\214\353\224\251.md" @@ -0,0 +1,73 @@ +```java +import java.util.*; +import java.io.*; + +public class boj6593 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());} + static int nextInt() {return Integer.parseInt(st.nextToken());} + + static Pos start, end; + static int L, R, C, answer; + static char[][][] map; + static int[][] dir = {{1,0,0}, {-1,0,0}, {0,1,0}, {0,-1,0}, {0,0,1}, {0,0,-1}}; + public static void main(String[] args) throws Exception { + while (true) { + nextLine(); + answer = Integer.MAX_VALUE; + L = nextInt(); + R = nextInt(); + C = nextInt(); + if (L == 0 && R == 0 && C == 0) return; + map = new char[L][R][C]; + for (int l = 0; l < L; l++) { + for (int r = 0; r < R; r++) { + String str = br.readLine(); + for (int c = 0; c < C; c++) { + map[l][r][c] = str.charAt(c); + if (map[l][r][c] == 'S') start = new Pos(l, r, c, 0); + else if (map[l][r][c] == 'E') end = new Pos(l, r, c, 0); + } + } + br.readLine(); + } + bfs(); + if (answer != Integer.MAX_VALUE) System.out.println("Escaped in "+answer+" minute(s)."); + else System.out.println("Trapped!"); + } + } + + static void bfs() { + boolean[][][] visited = new boolean[L][R][C]; + Queue q = new LinkedList<>(); + q.add(start); + while (!q.isEmpty()) { + Pos cur = q.poll(); + if ((cur.h == end.h) && (cur.r == end.r) && (cur.c == end.c)) { + answer = Math.min(answer, cur.cnt); + continue; + } + for (int[] d : dir) { + int nh = cur.h + d[0]; + int nr = cur.r + d[1]; + int nc = cur.c + d[2]; + if (nh < 0 || nh >= L || nr < 0 || nr >= R || nc < 0 || nc >= C) continue; + if (visited[nh][nr][nc] || map[nh][nr][nc] == '#') continue; + q.add(new Pos(nh, nr, nc, cur.cnt+1)); + visited[nh][nr][nc] = true; + } + } + } + + static class Pos { + int h, r, c, cnt; + public Pos(int h, int r, int c, int cnt) { + this.h = h; + this.r = r; + this.c = c; + this.cnt = cnt; + } + } +} +```