結果

問題 No.2946 Puyo
ユーザー Tamiji
提出日時 2024-12-23 22:26:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 520 ms / 2,000 ms
コード長 784 bytes
コンパイル時間 554 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 125,596 KB
最終ジャッジ日時 2024-12-23 22:26:26
合計ジャッジ時間 21,250 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
V=[[1]*w for _ in range(h)]
for i in range(h):
	for j in range(w):
		if V[i][j]:
			V[i][j]=0
			d=deque([(i,j)])
			A=[(i,j)]
			while d:
				p,q=d.popleft()
				if p and V[p-1][q] and S[p-1][q]==S[p][q]:
					d.append((p-1,q))
					V[p-1][q]=0
					A.append((p-1,q))
				if q and V[p][q-1] and S[p][q-1]==S[p][q]:
					d.append((p,q-1))
					V[p][q-1]=0
					A.append((p,q-1))
				if p<h-1 and V[p+1][q] and S[p+1][q]==S[p][q]:
					d.append((p+1,q))
					V[p+1][q]=0
					A.append((p+1,q))
				if q<w-1 and V[p][q+1] and S[p][q+1]==S[p][q]:
					d.append((p,q+1))
					V[p][q+1]=0
					A.append((p,q+1))
			if len(A)>=4:
				for x,y in A:
					S[x][y]='.'
for x in S:
	print(''.join(x))
0