From d912fc173a553ea3fd908ec6221cdd7d5ddd4edc Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Fri, 25 Jul 2025 09:28:58 +0900 Subject: [PATCH] =?UTF-8?q?[20250725]=20BOJ=20/=20G5=20/=20=EB=B3=B4?= =?UTF-8?q?=EB=AC=BC=EC=84=AC=20/=20=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5 \353\263\264\353\254\274\354\204\254.md" | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 "lkhyun/202507/25 BOJ G5 \353\263\264\353\254\274\354\204\254.md" diff --git "a/lkhyun/202507/25 BOJ G5 \353\263\264\353\254\274\354\204\254.md" "b/lkhyun/202507/25 BOJ G5 \353\263\264\353\254\274\354\204\254.md" new file mode 100644 index 00000000..e575f041 --- /dev/null +++ "b/lkhyun/202507/25 BOJ G5 \353\263\264\353\254\274\354\204\254.md" @@ -0,0 +1,63 @@ +```java +import java.util.*; +import java.io.*; + +public class Main{ + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N,M; + static char[][] map; + static List lands; + static int[] di = {0,0,-1,1}; + static int[] dj = {-1,1,0,0}; + static int ans = 0; + public static void main(String[] args) throws Exception { + st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + map = new char[N][M]; + lands = new LinkedList<>(); + + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < M; j++) { + map[i][j] = line.charAt(j); + if(map[i][j] == 'L'){ + lands.add(new int[]{i,j}); + } + } + } + + + for (int[] cur : lands) { + BFS(cur[0],cur[1]); + } + bw.write(ans+""); + bw.close(); + } + static void BFS(int starti, int startj){ + ArrayDeque q = new ArrayDeque<>(); + boolean[][] visited = new boolean[N][M]; + q.add(new int[]{starti,startj,0}); + visited[starti][startj] = true; + + while(!q.isEmpty()){ + int[] cur = q.poll(); + ans = Math.max(ans,cur[2]); + + for (int k = 0; k < 4; k++) { + int ni = cur[0] + di[k]; + int nj = cur[1] + dj[k]; + + if(ni<0 || ni>=N || nj<0 || nj>=M || visited[ni][nj]) continue; + + if(map[ni][nj] == 'L'){ + q.add(new int[]{ni,nj,cur[2]+1}); + visited[ni][nj] = true; + } + } + } + } +} +```