結果

問題 No.2946 Puyo
ユーザー miya145592
提出日時 2024-10-25 21:38:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 474 ms / 2,000 ms
コード長 840 bytes
コンパイル時間 453 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 120,744 KB
最終ジャッジ日時 2024-10-25 21:38:17
合計ジャッジ時間 15,726 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline
H, W = map(int, input().split())
G = [list(input().strip()) for _ in range(H)]
dir = [(1, 0), (0, 1), (-1, 0), (0, -1)]
for i in range(H):
    for j in range(W):
        if G[i][j]==".":
            continue
        deq = deque()
        deq.append((i, j))
        seen = set()
        seen.add((i, j))
        while deq:
            ci, cj = deq.popleft()
            for di, dj in dir:
                ni = ci+di
                nj = cj+dj
                if 0<=ni<H and 0<=nj<W:
                    if G[ci][cj]==G[ni][nj] and (ni, nj) not in seen:
                        deq.append((ni, nj))
                        seen.add((ni, nj))
        if len(seen)>=4:
            for ci, cj in seen:
                G[ci][cj] = "."
for i in range(H):
    print("".join(G[i]))
0