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); + } +} + +```