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++; + } + } +} +'''