結果
| 問題 |
No.2291 Union Find Estimate
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-05 21:58:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,755 bytes |
| コンパイル時間 | 304 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 77,184 KB |
| 最終ジャッジ日時 | 2024-11-23 07:30:24 |
| 合計ジャッジ時間 | 3,504 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 WA * 4 |
ソースコード
class Unionfind:
def __init__(self,n):
self.uf = [-1]*n
self.ps = [-1]*n
def find(self,x):
if self.uf[x] < 0:
return x
else:
self.uf[x] = self.find(self.uf[x])
return self.uf[x]
def same(self,x,y):
return self.find(x) == self.find(y)
def update(self,x,nx):
x = self.find(x)
ny = self.ps[x]
if nx != ny:
if nx != -1 and ny != -1:
self.ps[x] = 0
else:
self.ps[x] = max(nx,ny)
def union(self,x,y):
x = self.find(x)
y = self.find(y)
nx = self.ps[x]
ny = self.ps[y]
if x == y:
return False
if self.uf[x] > self.uf[y]:
x,y = y,x
self.uf[x] += self.uf[y]
self.uf[y] = x
if nx != ny:
if nx != -1 and ny != -1:
self.ps[x] = 0
else:
self.ps[x] = max(nx,ny)
return True
def size(self,x):
x = self.find(x)
return -self.uf[x]
w,h = map(int,input().split())
mod = 998244353
uf = Unionfind(w)
for i in range(h):
q = input()
last = [-1]*26
for j in range(w):
s = q[j]
if "0" <= s <= "9":
uf.update(j,int(s))
elif "a" <= s <= "z":
pos = ord(s)-ord("a")
if last[pos] == -1:
last[pos] = j
else:
uf.union(last[pos],j)
ans = 1
for j in range(w):
if uf.find(j) == j:
num = uf.ps[j]
if num == -1:
ans *= 10
elif num == 0:
ans = 0
break
ans %= mod
print(ans)