From e58edf3ee3cfd2bed14da1cfa341d7e1b1499a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Mon, 24 Nov 2025 10:23:33 +0900 Subject: [PATCH] =?UTF-8?q?[20251124]=20BOJ=20/=20G5=20/=20=EC=A0=81?= =?UTF-8?q?=EB=A1=9D=EC=83=89=EC=95=BD=20/=20=EA=B0=95=EC=8B=A0=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...01\353\241\235\354\203\211\354\225\275.md" | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 "ksinji/202511/24 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" diff --git "a/ksinji/202511/24 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" "b/ksinji/202511/24 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" new file mode 100644 index 00000000..42cf82a6 --- /dev/null +++ "b/ksinji/202511/24 BOJ \354\240\201\353\241\235\354\203\211\354\225\275.md" @@ -0,0 +1,89 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static char[][] map; + static boolean[][] visited; + + static int[] dy = {-1, 1, 0, 0}; + static int[] dx = {0, 0, -1, 1}; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + int n = Integer.parseInt(br.readLine()); + map = new char[n][n]; + visited = new boolean[n][n]; + + for (int i=0; i queue = new ArrayDeque<>(); + queue.add(new int[]{i, j}); + visited[i][j] = true; + + while (!queue.isEmpty()){ + int[] cur = queue.poll(); + + for (int k=0; k<4; k++){ + int nx = cur[0] + dx[k]; + int ny = cur[1] + dy[k]; + + if (nx < n && nx >= 0 && ny < n && ny >= 0 && !visited[nx][ny] + && map[cur[0]][cur[1]] == map[nx][ny]){ + visited[nx][ny] = true; + queue.add(new int[]{nx, ny}); + + } + } + } + count++; + } + } + } + + for (int i=0; i queue = new ArrayDeque<>(); + queue.add(new int[]{i, j}); + visited[i][j] = true; + + while (!queue.isEmpty()){ + int[] cur = queue.poll(); + + for (int k=0; k<4; k++){ + int nx = cur[0] + dx[k]; + int ny = cur[1] + dy[k]; + + if (nx < n && nx >= 0 && ny < n && ny >= 0 && !visited[nx][ny] + && ((map[cur[0]][cur[1]] == 'B' && map[nx][ny] == 'B') || (map[cur[0]][cur[1]] != 'B' && map[nx][ny] != 'B'))){ + visited[nx][ny] = true; + queue.add(new int[]{nx, ny}); + + } + } + } + rgcount++; + } + } + } + + System.out.println(count + " " + rgcount); + } +} +```