Skip to content

Commit 7be6343

Browse files
committed
[PGS] 프렌즈 4블록 / Level2 / 40분
1 parent 34b0596 commit 7be6343

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
def solution(m, n, board):
2+
answer = 0
3+
board = [list(row) for row in board]
4+
5+
while True:
6+
# 2x2 형태로 같은 블록이 있는지 확인
7+
blocks_to_remove = set()
8+
for i in range(m - 1):
9+
for j in range(n - 1):
10+
if board[i][j] == board[i][j + 1] == board[i + 1][j] == board[i + 1][j + 1] != '#':
11+
blocks_to_remove |= {(i, j), (i, j + 1), (i + 1, j), (i + 1, j + 1)}
12+
13+
if not blocks_to_remove:
14+
break
15+
16+
# 블록 제거
17+
for i, j in blocks_to_remove:
18+
board[i][j] = '#'
19+
answer += 1
20+
21+
# 블록이 떨어지는 과정
22+
for j in range(n):
23+
for i in range(m - 1, -1, -1):
24+
if board[i][j] == '#':
25+
for k in range(i - 1, -1, -1):
26+
if board[k][j] != '#':
27+
board[i][j], board[k][j] = board[k][j], '#'
28+
break
29+
30+
return answer

0 commit comments

Comments
 (0)