結果
問題 | No.2946 Puyo |
ユーザー |
![]() |
提出日時 | 2024-10-25 21:35:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 545 ms / 2,000 ms |
コード長 | 1,018 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 131,808 KB |
最終ジャッジ日時 | 2024-10-25 21:35:31 |
合計ジャッジ時間 | 15,304 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
import sys input = sys.stdin.readline H,W=map(int,input().split()) MAP=[list(input().strip()) for i in range(H)] # UnionFind Group = [i for i in range(H*W+1)] # グループ分け Nodes = [1]*(H*W+1) # 各グループのノードの数 def find(x): while Group[x] != x: x=Group[x] return x def Union(x,y): if find(x) != find(y): if Nodes[find(x)] < Nodes[find(y)]: Nodes[find(y)] += Nodes[find(x)] Nodes[find(x)] = 0 Group[find(x)] = find(y) else: Nodes[find(x)] += Nodes[find(y)] Nodes[find(y)] = 0 Group[find(y)] = find(x) for i in range(H): for j in range(W): if i+1<H and MAP[i][j]==MAP[i+1][j]: Union(i*W+j,(i+1)*W+j) if j+1<W and MAP[i][j]==MAP[i][j+1]: Union(i*W+j,i*W+(j+1)) for i in range(H): for j in range(W): if Nodes[find(i*W+j)]>=4: MAP[i][j]="." for i in range(H): print("".join(MAP[i]))