From 01891ab7813c50b38832992c378bdba7b2deceaf Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Thu, 11 Sep 2025 21:41:53 +0900 Subject: [PATCH] =?UTF-8?q?[20250911]=20BOJ=20/=20G5=20/=20=EB=86=8D?= =?UTF-8?q?=EC=9E=A5=20=EA=B4=80=EB=A6=AC=20/=20=EC=9D=B4=EC=A2=85?= =?UTF-8?q?=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\354\236\245 \352\264\200\353\246\254.md" | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 "0224LJH/202509/11 BOJ \353\206\215\354\236\245 \352\264\200\353\246\254.md" diff --git "a/0224LJH/202509/11 BOJ \353\206\215\354\236\245 \352\264\200\353\246\254.md" "b/0224LJH/202509/11 BOJ \353\206\215\354\236\245 \352\264\200\353\246\254.md" new file mode 100644 index 00000000..76ab54dd --- /dev/null +++ "b/0224LJH/202509/11 BOJ \353\206\215\354\236\245 \352\264\200\353\246\254.md" @@ -0,0 +1,81 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.*; + +public class Main { + static int height, width, ans; + static int[][] arr; + static boolean[][] visited; + static boolean isTop; + + static int[] dy = {-1,-1,0,1,1,1,0,-1}; + static int[] dx = {0,1,1,1,0,-1,-1,-1}; + + + public static void main(String[] args) throws NumberFormatException, IOException { + init(); + process(); + print(); + } + + public static void init() throws NumberFormatException, IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + height = Integer.parseInt(st.nextToken()); + width = Integer.parseInt(st.nextToken()); + + arr = new int[height][width]; + visited = new boolean[height][width]; + + for (int i = 0; i < height; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < width; j++) { + arr[i][j] =Integer.parseInt(st.nextToken()); + } + } + } + + public static void process() { + for (int i = 0; i < height; i++) { + for (int j = 0; j < width; j++) { + if (!visited[i][j]) { + isTop = true; + check(i,j); + if (isTop) ans++; + } + } + } + + } + + public static void check(int y, int x) { + int num = arr[y][x]; + visited[y][x] = true; + for (int i = 0; i < 8; i++) { + int ny = dy[i] + y; + int nx = dx[i] + x; + if (ny < 0 || nx < 0 || ny >= height || nx >= width) continue; + + int nNum = arr[ny][nx]; + + if (nNum < num) continue; + else if (nNum == num ) { + if (!visited[ny][nx])check(ny,nx); + } + else { + isTop = false; + continue; + } + } + } + + + + + public static void print() { + System.out.println(ans); + } +} +```