diff --git "a/YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" "b/YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" new file mode 100644 index 0000000..4db562f --- /dev/null +++ "b/YIM2UL2ET/BFS/13\354\260\250\354\213\234 - BOJ 7569.cpp" @@ -0,0 +1,50 @@ +#include +#include +#include + +struct idx {int z, y, x;}; + +int main(void) +{ + std::ios_base::sync_with_stdio(false); + std::cin.tie(NULL); + + int m, n, h, res = 0, non = 0; + std::vector offset = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}}; + std::queue que[2]; + bool curQueue = false; + + std::cin >> n >> m >> h; + int box[h][m][n]; + + for (int z = 0; z < h; z++) { + for (int y = 0; y < m; y++) { + for (int x = 0; x < n; x++) { + std::cin >> box[z][y][x]; + if (box[z][y][x] == 1) que[curQueue].push({z, y, x}); + else if (box[z][y][x] == 0) non++; + } + } + } + + while (!que[curQueue].empty() && non > 0) { + while (!que[curQueue].empty()) { + int z = que[curQueue].front().z, y = que[curQueue].front().y, x = que[curQueue].front().x; + for (idx set : offset) { + int zz = z + set.z, yy = y + set.y, xx = x + set.x; + if (zz >= 0 && zz < h && yy >= 0 && yy < m && xx >= 0 && xx < n && box[zz][yy][xx] == 0) { + box[zz][yy][xx] = 1, non--; + que[!curQueue].push({zz, yy, xx}); + } + } + que[curQueue].pop(); + } + curQueue = !curQueue; + res++; + } + + if (non > 0) std::cout << -1; + else std::cout << res; + + return 0; +} \ No newline at end of file diff --git a/YIM2UL2ET/README.md b/YIM2UL2ET/README.md index 32219bb..2431e6c 100644 --- a/YIM2UL2ET/README.md +++ b/YIM2UL2ET/README.md @@ -14,4 +14,5 @@ | 10차시 | 2024.03.10 | 스택 | [BOJ 1406](https://www.acmicpc.net/problem/1406) | [BOJ 1406 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/31) | | 11차시 | 2024.03.18 | 스택 | [BOJ 1918](https://www.acmicpc.net/problem/1918) | [BOJ 1918 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/36) | | 12차시 | 2024.03.28 | 비트마스킹 | [BOJ 11723](https://www.acmicpc.net/problem/11723) | [BOJ 11723 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/39) | +| 13차시 | 2024.04.01 | BFS | [BOJ 7569](https://www.acmicpc.net/problem/7569) | [BOJ 7569 풀이](https://github.com/AlgoLeadMe/AlgoLeadMe-7/pull/42) | ---