Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@
| 24์ฐจ์‹œ | 2025.04.30 | ๋ถ„ํ•  ์ •๋ณต | [ํ–‰๋ ฌ ์ œ๊ณฑ] | [#98](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/98) |
| 25์ฐจ์‹œ | 2025.05.11 | ๊ทธ๋ฆฌ๋”” ์•Œ๊ณ ๋ฆฌ์ฆ˜ | [ํŒ”](https://www.acmicpc.net/problem/1105) | [#100](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/100) |
| 26์ฐจ์‹œ | 2025.05.19 | ๋ถ„ํ•  ์ •๋ณต | [๋ณ„ ์ฐ๊ธฐ - 10](https://www.acmicpc.net/problem/2447) | [#102](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/102) |
<<<<<<< Updated upstream
=======
| 28์ฐจ์‹œ | 2025.07.01 | ๊ตฌํ˜„ | [์Šค๋„์ฟ ](https://www.acmicpc.net/problem/2580) |[#116](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/116) |
| 29์ฐจ์‹œ | 2025.07.21 | ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰ | [๋ถˆ!](https://www.acmicpc.net/problem/4179) |[#118](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/118) |
<<<<<<< Updated upstream
>>>>>>> Stashed changes
=======
>>>>>>> Stashed changes
---
84 changes: 84 additions & 0 deletions kokeunho/๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰/29-kokeunho.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import java.util.*;

public class Main {
static int R, C;
static int escapeCount = Integer.MAX_VALUE;
static char[][] map;
static int[][] fireCount;
static boolean[][] visited;
static int[] dx = {-1, 1, 0, 0};
static int[] dy = {0, 0, -1, 1};

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);

R = sc.nextInt();
C = sc.nextInt();
map = new char[R][C];
List<int[]> firePos = new ArrayList<>();
int jx = 0, jy = 0;
for (int i = 0; i < R; i++) {
String line = sc.next();
for (int j = 0; j < C; j++) {
map[i][j] = line.charAt(j);
if (map[i][j] == 'J') {
jx = i;
jy = j;
}
if (map[i][j] == 'F') {
firePos.add(new int[]{i, j});
}
}
}
fireCount = new int[R][C];
for (int i = 0; i < R; i++) {
Arrays.fill(fireCount[i], Integer.MAX_VALUE);
}
for (int[] pos : firePos) {
fireBfs(pos[0], pos[1]);
}
visited = new boolean[R][C];
jihoonBfs(jx, jy);

System.out.println(escapeCount == Integer.MAX_VALUE ? "IMPOSSIBLE" : escapeCount);
}
static void fireBfs (int x, int y) {
Queue<int[]> queue = new LinkedList<>();
fireCount[x][y] = 0;
queue.add(new int[]{x, y});

while(!queue.isEmpty()) {
int[] current = queue.poll();
for (int i = 0; i < 4; i++) {
int nx = current[0] + dx[i];
int ny = current[1] + dy[i];
if (nx >= 0 && nx < R && ny >= 0 && ny < C
&& fireCount[nx][ny] > fireCount[current[0]][current[1]]+1 && map[nx][ny] != '#') {
queue.add(new int[]{nx, ny});
fireCount[nx][ny] = fireCount[current[0]][current[1]]+1;
}
}
}
}
static void jihoonBfs (int x, int y) {
Queue<int[]> queue = new LinkedList<>();
visited[x][y] = true;
queue.add(new int[]{x, y, 0});

while(!queue.isEmpty()) {
int[] current = queue.poll();
for (int i = 0; i < 4; i++) {
int nx = current[0] + dx[i];
int ny = current[1] + dy[i];
if (nx < 0 || nx >= R || ny < 0 || ny >= C) {
escapeCount = Math.min(escapeCount, current[2] + 1);
continue;
Comment on lines +73 to +75
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ‰ํ–‰์„ธ๊ณ„?์ค‘ ๊ฐ€์žฅ ๋นจ๋ฆฌ ๋‚˜์˜จ ์ง€ํ›ˆ์ด์ž„์ด ๋ณด์žฅ๋จ์œผ๋กœ ๋ฐ”๋กœ current[2] + 1 ๊ฐ’์„ escapeCount๋กœ ๋‘๊ณ  returnํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค.
์šฐ์„ ์ˆœ์œ„ํ๊ฐ€ ์•„๋‹ˆ์–ด๋„ ํ๋Š” ์ˆœ์„œ๋Œ€๋กœ ์Œ“์ด๋‹ˆ๊นŒ์š”

}
if (!visited[nx][ny] && map[nx][ny] != '#' && current[2] + 1 < fireCount[nx][ny]) {
queue.add(new int[]{nx, ny, current[2] + 1});
visited[nx][ny] = true;
}
}
}
}
}