結果

問題 No.2946 Puyo
ユーザー titia
提出日時 2024-10-25 21:34:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,018 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 65,852 KB
最終ジャッジ日時 2024-10-25 21:35:25
合計ジャッジ時間 44,343 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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]))
0