From ed3c2f99034522158a0079f02396fd9e3f7d9cc8 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Mon, 1 Sep 2025 17:42:16 +0900 Subject: [PATCH] =?UTF-8?q?[20250901]=20BOJ=20/=20G3=20/=20=EC=9C=A1?= =?UTF-8?q?=EA=B0=81=20=EB=B3=B4=EB=93=9C/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\352\260\201 \353\263\264\353\223\234.md" | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 "Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" diff --git "a/Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" "b/Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" new file mode 100644 index 00000000..ec33577e --- /dev/null +++ "b/Ukj0ng/202509/1 BOJ G3 \354\234\241\352\260\201 \353\263\264\353\223\234.md" @@ -0,0 +1,71 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final int[] dx = {1, 1, 0, 0, -1, -1}; + private static final int[] dy = {0, -1, 1, -1, 0, 1}; + private static char[][] board; + private static int[][] arr; + private static int N, color; + + public static void main(String[] args) throws IOException { + init(); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + if (board[i][j] == 'X' && arr[i][j] == 0) { + color = Math.max(color, 1); + BFS(i, j); + } + } + } + + bw.write(color + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + color = 0; + board = new char[N][N]; + arr = new int[N][N]; + + for (int i = 0; i < N; i++) { + board[i] = br.readLine().toCharArray(); + } + } + + private static void BFS(int x, int y) { + Queue q = new ArrayDeque<>(); + arr[x][y] = 1; + q.add(new int[]{x, y}); + + while (!q.isEmpty()) { + int[] current = q.poll(); + + for (int i = 0; i < 6; i++) { + int nx = current[0] + dx[i]; + int ny = current[1] + dy[i]; + + if (OOB(nx, ny) || board[nx][ny] != 'X') continue; + if (arr[nx][ny] == 0) { + color = Math.max(color, 2); + arr[nx][ny] = 3 - arr[current[0]][current[1]]; + q.add(new int[]{nx, ny}); + } else if (arr[nx][ny] == arr[current[0]][current[1]]) { + color = Math.max(color, 3); + return; + } + } + } + } + + private static boolean OOB(int nx, int ny) { + return nx < 0 || nx > N-1 || ny < 0 || ny > N-1; + } +} +```