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