結果
問題 | No.2946 Puyo |
ユーザー |
![]() |
提出日時 | 2024-10-25 21:39:50 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 1,912 ms / 2,000 ms |
コード長 | 779 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 28,900 KB |
最終ジャッジ日時 | 2024-10-25 21:40:36 |
合計ジャッジ時間 | 39,156 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
class UF: def __init__(self,n): self.p = [-1]*n def f(self,x): if self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def n(self,x): return -self.p[self.f(x)] h,w = map(int,input().split()) g = [list(input()) for _ in range(h)] uf = UF(h*w) for i in range(h): for j in range(w-1): if g[i][j]==g[i][j+1]: uf.u(i*w+j,i*w+(j+1)) for j in range(w): for i in range(h-1): if g[i][j]==g[i+1][j]: uf.u(i*w+j,(i+1)*w+j) for i in range(h): for j in range(w): if uf.n(i*w+j)>=4: g[i][j] = "." for a in g: print("".join(a))