結果
| 問題 | 
                            No.2946 Puyo
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2024-10-28 22:07:30 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 392 ms / 2,000 ms | 
| コード長 | 871 bytes | 
| コンパイル時間 | 219 ms | 
| コンパイル使用メモリ | 82,068 KB | 
| 実行使用メモリ | 117,116 KB | 
| 最終ジャッジ日時 | 2024-10-28 22:07:46 | 
| 合計ジャッジ時間 | 14,629 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 45 | 
ソースコード
from collections import deque
h,w=map(int,input().split())
grid=[list(input()) for _ in range(h)]
move=[(1,0),(0,1),(0,-1),(-1,0)]
for i in range(h):
    for j in range(w):
        change=[]
        que=deque()
        if grid[i][j]!=".":
            word=grid[i][j]
            que.append((i,j))
            change.append((i,j))
            grid[i][j]="."
            while que:
                nowx,nowy=que.popleft()
                for x,y in move:
                    if 0<=nowx+x<h and 0<=nowy+y<w:
                        if grid[nowx+x][nowy+y]==word:
                            grid[nowx+x][nowy+y]="."
                            que.append((nowx+x,nowy+y))
                            change.append((nowx+x,nowy+y))
            if len(change)<4:
                for x,y in change:
                    grid[x][y]=word
for ans in grid:
    print("".join(ans))