結果
問題 | 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]*nself.ps = [-1]*ndef find(self,x):if self.uf[x] < 0:return xelse: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] = 0else: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 Falseif self.uf[x] > self.uf[y]:x,y = y,xself.uf[x] += self.uf[y]self.uf[y] = xif nx != ny:if nx != -1 and ny != -1:self.ps[x] = 0else:self.ps[x] = max(nx,ny)return Truedef size(self,x):x = self.find(x)return -self.uf[x]w,h = map(int,input().split())mod = 998244353uf = Unionfind(w)for i in range(h):q = input()last = [-1]*26for 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] = jelse:uf.union(last[pos],j)ans = 1for j in range(w):if uf.find(j) == j:num = uf.ps[j]if num == -1:ans *= 10elif num == 0:ans = 0breakans %= modprint(ans)