From f980d2e89c57a9b18288e4c854a342c8e48e9273 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 19 Mar 2026 20:42:20 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[20260311]=20BOJ=20/=20G5=20/=20=EA=B3=B5?= =?UTF-8?q?=EC=A3=BC=EB=8B=98=EC=9D=84=20=EA=B5=AC=ED=95=B4=EB=9D=BC!=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \352\265\254\355\225\264\353\235\274!.md" | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 "JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" diff --git "a/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" "b/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" new file mode 100644 index 00000000..0bd5d773 --- /dev/null +++ "b/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" @@ -0,0 +1,78 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int N, M, T; + static int[][] map; + static boolean[][] visited; + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + T = Integer.parseInt(st.nextToken()); + + map = new int[N][M]; + visited = new boolean[N][M]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < M; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + int result = bfs(); + + if (result == -1) System.out.println("Fail"); + else System.out.println(result); + } + + static int bfs() { + Queue q = new LinkedList<>(); + q.add(new int[]{0, 0, 0}); + visited[0][0] = true; + + int findGram = Integer.MAX_VALUE; + int res = Integer.MAX_VALUE; + + while (!q.isEmpty()) { + int[] cur = q.poll(); + int x = cur[0]; + int y = cur[1]; + int time = cur[2]; + + if (time > T) break; + + if (x == N - 1 && y == M - 1) { + res = time; + break; + } + + for (int i = 0; i < 4; i++) { + int nx = x + dx[i]; + int ny = y + dy[i]; + + if (nx >= 0 && nx < N && ny >= 0 && ny < M && !visited[nx][ny]) { + if (map[nx][ny] == 2) { + visited[nx][ny] = true; + findGram = time + 1 + Math.abs(N - 1 - nx) + Math.abs(M - 1 - ny); + } + else if (map[nx][ny] == 0) { + visited[nx][ny] = true; + q.add(new int[]{nx, ny, time + 1}); + } + } + } + } + + int finalMin = Math.min(findGram, res); + return (finalMin <= T) ? finalMin : -1; + } +} +``` From 52bb04c9219758527c832efb9773eca6d2cba8ea Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Thu, 19 Mar 2026 20:42:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[20260319]=20BOJ=20/=20G5=20/=20=EA=B3=B5?= =?UTF-8?q?=EC=A3=BC=EB=8B=98=EC=9D=84=20=EA=B5=AC=ED=95=B4=EB=9D=BC!=20/?= =?UTF-8?q?=20=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" "b/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" index 0bd5d773..31553ab4 100644 --- "a/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" +++ "b/JHLEE325/202603/19 BOJ G5 \352\263\265\354\243\274\353\213\230\354\235\204 \352\265\254\355\225\264\353\235\274!.md" @@ -3,6 +3,7 @@ import java.io.*; import java.util.*; public class Main { + static int N, M, T; static int[][] map; static boolean[][] visited;