結果

問題 No.2946 Puyo
ユーザー cologne
提出日時 2025-04-28 13:19:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 571 ms / 2,000 ms
コード長 1,245 bytes
コンパイル時間 514 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 124,672 KB
最終ジャッジ日時 2025-04-28 13:20:17
合計ジャッジ時間 18,428 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left, bisect_right
from collections import defaultdict, deque
import math
import sys


def input():
    return sys.stdin.readline().strip()


def main():
    h, w = map(int, input().split())
    a = [list(input()) for _ in range(h)]
    vis = [[False] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if not vis[i][j]:
                q = deque([(i, j)])
                vis[i][j] = True
                comp = [(i, j)]
                while q:
                    x, y = q.popleft()
                    for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
                        nx, ny = x + dx, y + dy
                        if (
                            0 <= nx < h
                            and 0 <= ny < w
                            and not vis[nx][ny]
                            and a[nx][ny] == a[x][y]
                        ):
                            vis[nx][ny] = True
                            q.append((nx, ny))
                            comp.append((nx, ny))

                if len(comp) >= 4:
                    for x, y in comp:
                        a[x][y] = "."

    for x in a:
        print("".join(x))


if __name__ == "__main__":
    main()
0