From d4dd6b9dcb2f2f4443141f599804729b77307938 Mon Sep 17 00:00:00 2001 From: DaeWook Kim Date: Sun, 21 Dec 2025 23:45:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=202025-12-22=20baekjoon=207569=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daewook/2025-12-22_baekjoon_7569.cpp | 82 ++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 daewook/2025-12-22_baekjoon_7569.cpp diff --git a/daewook/2025-12-22_baekjoon_7569.cpp b/daewook/2025-12-22_baekjoon_7569.cpp new file mode 100644 index 0000000..29f2c73 --- /dev/null +++ b/daewook/2025-12-22_baekjoon_7569.cpp @@ -0,0 +1,82 @@ +#include +#include + +using namespace std; + +int m, n, h; + +// 가로 x 세로 x 높이 +int tomato[100][100][100]; + +int dx[6] = {1, -1, 0, 0, 0, 0}; +int dy[6] = {0, 0, 1, -1, 0, 0}; +int dz[6] = {0, 0, 0, 0, 1, -1}; + +struct Tomato { + int x, y, z, day; +}; + +queue q; + +int bfs() { + int maxDay = 0; + + while (!q.empty()) { + auto [nx, ny, nz, day] = q.front(); + q.pop(); + + maxDay = max(maxDay, day); + + for (int i = 0; i < 6; i++) { + int cx = nx + dx[i]; + int cy = ny + dy[i]; + int cz = nz + dz[i]; + + if (cx < 0 || cy < 0 || cz < 0 || cx >=m || cy >= n || cz >= h) + continue; + + if (tomato[cx][cy][cz] == 0) { + tomato[cx][cy][cz] = 1; + q.push({cx, cy, cz, day + 1}); + } + } + } + + return maxDay; +} + +int main() { + + ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> m >> n >> h; + + // 초기 tomato 값 채우기 + for (int z = 0; z < h; z++) { + for (int y = 0; y < n; y++) { + for (int x = 0; x < m; x++) { + cin >> tomato[x][y][z]; + + if (tomato[x][y][z] == 1) + q.push({x, y, z, 0}); + } + } + } + + int days = bfs(); + + for (int z = 0; z < h; z++) { + for (int y = 0; y < n; y++) { + for (int x = 0; x < m; x++) { + if (tomato[x][y][z] == 0) { + cout << -1 << "\n"; + return 0; + } + } + } + } + + cout << days << "\n"; + return 0; +} \ No newline at end of file