From 6cc3a7d0d1fb7cb5be368bc0e8ecc4a56eb63ce3 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 9 Sep 2025 21:10:33 +0900 Subject: [PATCH] =?UTF-8?q?[20250909]=20PGM=20/=20LV2=20/=20[1=EC=B0=A8]?= =?UTF-8?q?=20=ED=94=84=EB=A0=8C=EC=A6=884=EB=B8=94=EB=A1=9D=20/=20?= =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\246\2104\353\270\224\353\241\235.md" | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 "suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" diff --git "a/suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" "b/suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" new file mode 100644 index 00000000..986e8d35 --- /dev/null +++ "b/suyeun84/202509/09 PGM LV2 [1\354\260\250] \355\224\204\353\240\214\354\246\2104\353\270\224\353\241\235.md" @@ -0,0 +1,74 @@ + ```java +import java.util.*; +class Solution { + static int[][] dir = new int[][]{{0,0}, {0, 1}, {1,0}, {1,1}}; + static int M, N, answer = 0; + static char[][] map; + public int solution(int m, int n, String[] board) { + M = m; + N = n; + map = new char[M][N]; + for (int i = 0; i < m; i++) { + for (int j = 0; j < n; j++) { + map[i][j] = board[i].charAt(j); + } + } + boolean flag = true; + while (flag) { + flag = check(); + } + return answer; + } + // 없앨 수 있는 block 찾기 + private boolean check() { + boolean[][] remove = new boolean[M][N]; + boolean flag = false; + for (int i = 0; i < M-1; i++) { + for (int j = 0; j < N-1; j++) { + char curr = map[i][j]; + if (curr == '0') continue; + if (curr == map[i+1][j] && curr == map[i][j+1] && curr == map[i+1][j+1]) { + for (int[] d : dir) { + int ny = i + d[0]; + int nx = j + d[1]; + if (!remove[ny][nx]) answer++; + remove[ny][nx] = true; + } + flag = true; + } + } + } + if (flag) move(remove); + return flag; + } + + private void move(boolean[][] remove) { + for (int j = 0; j < N; j++) { // 각 열마다 + Stack stack = new Stack<>(); + + for (int i = 0; i < M; i++) { + if (!remove[i][j] && map[i][j] != '0') { + stack.push(map[i][j]); + } + } + + for (int i = M - 1; i >= 0; i--) { + if (!stack.isEmpty()) { + map[i][j] = stack.pop(); + } else { + map[i][j] = '0'; + } + } + } + } + + + class Point { + int y, x; + public Point(int y, int x) { + this.y = y; + this.x = x; + } + } +} +```