From 5a96218f06c65219bbbc00d439c6a333b524091e Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Fri, 11 Jul 2025 16:38:39 +0900 Subject: [PATCH] =?UTF-8?q?[20250711]=20BOJ=20/=20G5=20/=20=ED=86=A0?= =?UTF-8?q?=EB=A7=88=ED=86=A0=20/=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...J G5 \355\206\240\353\247\210\355\206\240" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "JHLEE325/202507/11 BOJ G5 \355\206\240\353\247\210\355\206\240" diff --git "a/JHLEE325/202507/11 BOJ G5 \355\206\240\353\247\210\355\206\240" "b/JHLEE325/202507/11 BOJ G5 \355\206\240\353\247\210\355\206\240" new file mode 100644 index 00000000..7064e928 --- /dev/null +++ "b/JHLEE325/202507/11 BOJ G5 \355\206\240\353\247\210\355\206\240" @@ -0,0 +1,72 @@ +'''java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayDeque; +import java.util.Queue; +import java.util.StringTokenizer; + +public class Main { + static Queue list = new ArrayDeque<>(); + static int count, m, n, h; + static int[][] dir = {{-1, 0, 0}, {1, 0, 0}, {0, -1, 0}, {0, 1, 0}, {0, 0, -1}, {0, 0, 1}}; + static int[][][] box; + static int day = -1; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + m = Integer.parseInt(st.nextToken()); + n = Integer.parseInt(st.nextToken()); + h = Integer.parseInt(st.nextToken()); + + box = new int[n][m][h]; + + for (int height = 0; height < h; height++) { + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < m; j++) { + box[i][j][height] = Integer.parseInt(st.nextToken()); + if (box[i][j][height] == 0) count++; + if (box[i][j][height] == 1) list.add(new int[]{i, j, height}); + } + } + } + + tomato(); + + if (count == 0) + System.out.println(day); + else System.out.println("-1"); + } + + static void tomato() { + while (!list.isEmpty()) { + int s = list.size(); + for (int i = 0; i < s; i++) { + int[] cur = list.poll(); + int y = cur[0]; + int x = cur[1]; + int he = cur[2]; + + for (int d = 0; d < 6; d++) { + int dy = y + dir[d][0]; + int dx = x + dir[d][1]; + int dh = he + dir[d][2]; + + if (dy < 0 || dy >= n || dx < 0 || dx >= m || dh < 0 || dh >= h) + continue; + + if (box[dy][dx][dh] == 0) { + count--; + box[dy][dx][dh] = 1; + list.add(new int[]{dy, dx, dh}); + } + } + } + day++; + } + } +} +'''