From 9e4c426a417ae9dfecfa5d014439dda7ff481d56 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Sun, 24 Aug 2025 23:18:11 +0900 Subject: [PATCH] =?UTF-8?q?[20250824]=20PGM=20/=20LV2=20/=20=EC=84=9D?= =?UTF-8?q?=EC=9C=A0=20=EC=8B=9C=EC=B6=94=20/=20=EC=9D=B4=EC=9D=B8?= =?UTF-8?q?=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\354\234\240 \354\213\234\354\266\224.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" diff --git "a/LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" "b/LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" new file mode 100644 index 00000000..e4b7c928 --- /dev/null +++ "b/LiiNi-coder/202508/25 PGM \354\204\235\354\234\240 \354\213\234\354\266\224.md" @@ -0,0 +1,74 @@ +```java +import java.util.*; + +class Solution { + private static int R + private static int C; + private static int[][] land; + private static int[][] idAtPoint; + private static boolean[][] visited; + private static int[] dr = {1, -1, 0, 0}; + private static int[] dc = {0, 0, 1, -1}; + private static List countAtId; + + public int solution(int[][] lland) { + land = lland; + R = land.length; + C = land[0].length; + visited = new boolean[R][C]; + idAtPoint = new int[R][C]; + countAtId = new ArrayList<>(); + countAtId.add(0);//0생략 + int id = 1; + for(int r=0; r(); + for(int r=0; r(); + q.add(new int[]{sr, sc}); + visited[sr][sc] = true; + idAtPoint[sr][sc] = id; + + int temp = 0; + while(!q.isEmpty()){ + int[] cur = q.poll(); + int r = cur[0] + int c = cur[1]; + temp++; + for(int d=0; d<4; d++){ + int nr = r + dr[d]; + int nc = c + dc[d]; + if(nr<0 || nr>=R || nc<0 || nc>=C) continue; + if(visited[nr][nc]) continue; + if(land[nr][nc] == 0) continue; + visited[nr][nc] = true; + idAtPoint[nr][nc] = id; + q.add(new int[]{nr, nc}); + } + } + countAtId.add(temp); + } +} + +```