From 60f7771e3703eea70314c177ba6ea6b30ac4c1cc Mon Sep 17 00:00:00 2001 From: DaeWook Kim Date: Tue, 9 Dec 2025 16:43:19 +0900 Subject: [PATCH] =?UTF-8?q?feat:=202025-12-09=20beakjoon=204179=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-09_baekjoon_4179.cpp | 84 ++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 daewook/2025-12-09_baekjoon_4179.cpp diff --git a/daewook/2025-12-09_baekjoon_4179.cpp b/daewook/2025-12-09_baekjoon_4179.cpp new file mode 100644 index 0000000..0131d0d --- /dev/null +++ b/daewook/2025-12-09_baekjoon_4179.cpp @@ -0,0 +1,84 @@ +#include +#include + +using namespace std; + +int r, c; +char miro[1000][1000]; +int jh[1000][1000]; +int fire[1000][1000]; + +int dx[4] = {1, -1, 0, 0}; +int dy[4] = {0, 0, 1, -1}; + +int main() { + cin >> r >> c; + + queue> q1; // 지훈 + queue> q2; // 불 + + for (int i = 0; i < r; i++) { + for (int j = 0; j < c; j++) { + cin >> miro[i][j]; + + if (miro[i][j] == 'J') { + q1.push({i, j}); + jh[i][j] = 1; + } + + else if (miro[i][j] == 'F') { + q2.push({i, j}); + fire[i][j] = 1; + } + } + } + + // 불 bfs + while (!q2.empty()) { + auto [nx, ny] = q2.front(); + q2.pop(); + + for (int i = 0; i < 4; i++) { + int cx = nx + dx[i]; + int cy = ny + dy[i]; + + if (cx < 0 || cy < 0 || cx >= r || cy >= c) + continue; + + if (miro[cx][cy] != '#' && fire[cx][cy] == 0) { + q2.push({cx, cy}); + fire[cx][cy] = fire[nx][ny] + 1; + } + } + } + + // 지훈 bfs + while (!q1.empty()) { + auto [nx, ny] = q1.front(); + q1.pop(); + + if (nx == 0 || ny == 0 || nx == r-1 || ny == c-1) { + cout << jh[nx][ny]; + return 0; + } + + for (int i = 0; i < 4; i++) { + int cx = nx + dx[i]; + int cy = ny + dy[i]; + + if (cx < 0 || cy < 0 || cx >= r || cy >= c) + continue; + + if (miro[cx][cy] == '#' || jh[cx][cy]) + continue; + + if (fire[cx][cy] != 0 && fire[cx][cy] <= jh[nx][ny] + 1) + continue; + + q1.push({cx, cy}); + jh[cx][cy] = jh[nx][ny] + 1; + } + } + cout << "IMPOSSIBLE"; + return 0; +} \ No newline at end of file