From 6c30615fd813ba6536770e1eb7b57978c59f0972 Mon Sep 17 00:00:00 2001 From: kokeunho Date: Mon, 20 Jan 2025 01:23:29 +0900 Subject: [PATCH] =?UTF-8?q?2025-01-20/=EC=95=88=EC=A0=84=20=EC=98=81?= =?UTF-8?q?=EC=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kokeunho/.DS_Store | Bin 6148 -> 6148 bytes kokeunho/README.md | 1 + .../17-kokeunho.java" | 51 ++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 "kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/17-kokeunho.java" diff --git a/kokeunho/.DS_Store b/kokeunho/.DS_Store index 425536b2cf9f3dc3d5efcbbdd8826438d16f20ad..993dfd2ac4439b7ae33690e5048d694750c11291 100644 GIT binary patch delta 95 zcmZoMXffEZl7(@{>2%#Bxp)`!@-kid^m}xUB$A5kRbN>_r delta 97 zcmZoMXffEZl7(^CJA-x`svu209AH#)h>z3e}cIK(>joS#2#Rhp4i?bx?eE gPHtX)4+9u5GD2tuUMLNtdN(JrE@s-y&heKY0GwkKTL1t6 diff --git a/kokeunho/README.md b/kokeunho/README.md index b555e9d..bc5fbdc 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -18,4 +18,5 @@ | 14차시 | 2025.01.08 | 그래프 탐색 | [미로만들기](https://www.acmicpc.net/problem/2665) | [#55](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/55) | | 15차시 | 2025.01.12 | 조합론 | [격자상의 경로](https://www.acmicpc.net/problem/10164) | [#58](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/58) | | 16차시 | 2025.01.19 | 그래프 탐색 | [DFS와 BFS](https://www.acmicpc.net/problem/1260) | [#63](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/63) | +| 17차시 | 2025.01.20 | 그래프 탐색 | [안전 영역](https://www.acmicpc.net/problem/2468) | [#64](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/64) | --- diff --git "a/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/17-kokeunho.java" "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/17-kokeunho.java" new file mode 100644 index 0000000..4083838 --- /dev/null +++ "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/17-kokeunho.java" @@ -0,0 +1,51 @@ +import java.util.*; + +public class Main { + static int n; + static int[][] map; + static boolean[][] visited; + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + + n = sc.nextInt(); + map = new int[n][n]; + visited = new boolean[n][n]; + + int max_height = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + map[i][j] = sc.nextInt(); + max_height = Math.max(max_height, map[i][j]); + } + } + + int max_area = 0; + for (int h = 0; h <= max_height; h++) { + visited = new boolean[n][n]; + int safe_area = 0; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (!visited[i][j] && map[i][j] > h) { + dfs(i, j, h); + safe_area++; + } + } + } + max_area = Math.max(max_area, safe_area); + } + System.out.print(max_area); + } + public static void dfs(int startX, int startY, int height) { + visited[startX][startY] = true; + for (int i = 0; i < 4; i++) { + int nx = startX + dx[i]; + int ny = startY + dy[i]; + if (nx >= 0 && nx < n && ny >= 0 && ny < n && !visited[nx][ny] && map[nx][ny] > height) { + dfs(nx, ny, height); + } + } + } +} \ No newline at end of file