diff --git a/kokeunho/.DS_Store b/kokeunho/.DS_Store deleted file mode 100644 index 1256d34..0000000 Binary files a/kokeunho/.DS_Store and /dev/null differ diff --git a/kokeunho/README.md b/kokeunho/README.md index c4b912d..fb6a532 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -32,4 +32,5 @@ | 29차시 | 2025.07.21 | 그래프 탐색 | [불!](https://www.acmicpc.net/problem/4179) |[#118](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/118) | | 30차시 | 2025.07.26 | 그래프 탐색 | [중량제한](https://www.acmicpc.net/problem/1939) |[#120](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/120) | | 31차시 | 2025.08.03 | 그래프 탐색 | [면접보는 승범이네](https://www.acmicpc.net/problem/17835) | [#126](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/126) | +| 32차시 | 2025.08.10 | 그래프 탐색 | [석유 시추](https://school.programmers.co.kr/learn/courses/30/lessons/250136) |[#129](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/129) | --- diff --git "a/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/32-kokeunho.java" "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/32-kokeunho.java" new file mode 100644 index 0000000..44c13a6 --- /dev/null +++ "b/kokeunho/\352\267\270\353\236\230\355\224\204 \355\203\220\354\203\211/32-kokeunho.java" @@ -0,0 +1,57 @@ +import java.util.*; + +class Solution { + static int col, row; + static int[] dx = {-1, 1, 0, 0}; + static int[] dy = {0, 0, -1, 1}; + static int[] sumAreaPerCol; + static boolean[][] visited; + + public int solution(int[][] land) { + col = land[0].length; + row = land.length; + sumAreaPerCol = new int[col]; + visited = new boolean[row][col]; + + for (int i = 0; i < col; i++) { + for (int j = 0; j < row; j++) { + if (land[j][i] == 1 && !visited[j][i]) { + bfs(j, i, land); + } + } + } + + int maxArea = 0; + for (int i = 0; i < col; i++) { + maxArea = Math.max(maxArea, sumAreaPerCol[i]); + } + return maxArea; + } + public void bfs(int x, int y, int[][] land) { + Queue queue = new LinkedList<>(); + queue.add(new int[]{x, y}); + visited[x][y] = true; + int area = 1; + Set colList = new HashSet<>(); + colList.add(y); + + while(!queue.isEmpty()) { + int[] current = queue.poll(); + + for (int i = 0; i < 4; i++) { + int nx = current[0] + dx[i]; + int ny = current[1] + dy[i]; + if (nx >= 0 && nx < row && ny >= 0 && ny < col && !visited[nx][ny] && land[nx][ny] == 1) { + queue.add(new int[]{nx, ny}); + visited[nx][ny] = true; + area++; + colList.add(ny); + } + } + } + + for (int column : colList) { + sumAreaPerCol[column] += area; + } + } +} \ No newline at end of file