From 0a9fa53eefb7d9e37f865fa8dae0907cc65052b6 Mon Sep 17 00:00:00 2001 From: YoonYn9915 Date: Sun, 1 Jun 2025 10:52:05 +0900 Subject: [PATCH] =?UTF-8?q?[BOJ]=20Puyo=20Puyo=20/=20=EA=B3=A8=EB=93=9C=20?= =?UTF-8?q?4=20/=2080=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://www.acmicpc.net/problem/11559 --- ...\260\261\354\244\200]-#11559 Puyo Puyo.py" | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 "YoonYn9915/implementation/2025-05-29-[\353\260\261\354\244\200]-#11559 Puyo Puyo.py" diff --git "a/YoonYn9915/implementation/2025-05-29-[\353\260\261\354\244\200]-#11559 Puyo Puyo.py" "b/YoonYn9915/implementation/2025-05-29-[\353\260\261\354\244\200]-#11559 Puyo Puyo.py" new file mode 100644 index 0000000..daa81ae --- /dev/null +++ "b/YoonYn9915/implementation/2025-05-29-[\353\260\261\354\244\200]-#11559 Puyo Puyo.py" @@ -0,0 +1,60 @@ +from collections import deque +from sys import stdin +input = stdin.readline + +EMPTY = '.' +dx = (1, -1, 0, 0) +dy = (0, 0, 1, -1) + + +def delete_block(): + for x, y in blocks: + board[x][y] = EMPTY + + +def update_board(): + for y in range(6): + for t in range(10, -1, -1): + for x in range(11, t, -1): + if board[x][y] == EMPTY and board[t][y] != EMPTY: + board[x][y], board[t][y] = board[t][y], EMPTY + + +def is_in_area(x, y): + return 0 <= x < 12 and 0 <= y < 6 + + +def bfs(x, y): + queue = deque([(x, y)]) + visited[x][y] = True + same_blocks = [(x, y)] + while queue: + x, y = queue.popleft() + for d in range(4): + nx = x + dx[d] + ny = y + dy[d] + if is_in_area(nx, ny) and not visited[nx][ny] and board[x][y] == board[nx][ny]: + queue.append((nx, ny)) + visited[nx][ny] = True + same_blocks.append((nx, ny)) + return same_blocks + + + +board = [[*input().rstrip()] for _ in range(12)] +flag = True +res = 0 +while flag: + flag = False + visited = [[False] * 6 for _ in range(12)] + for i in range(12): + for j in range(6): + if board[i][j] != EMPTY and not visited[i][j]: + blocks = bfs(i, j) + if len(blocks) >= 4: + flag = True + delete_block() + if flag: + update_board() + res += 1 +print(res) \ No newline at end of file