結果
問題 | No.2291 Union Find Estimate |
ユーザー |
![]() |
提出日時 | 2023-05-05 21:51:27 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 878 bytes |
コンパイル時間 | 331 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 23,676 KB |
最終ジャッジ日時 | 2024-11-23 07:00:34 |
合計ジャッジ時間 | 9,016 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 TLE * 1 |
ソースコード
class UF:def __init__(self,n):self.p = [-1]*ndef f(self,x):if self.p[x]<0: return xelse: 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: returnif -self.p[x]<-self.p[y]: x,y = y,xself.p[x] += self.p[y]; self.p[y] = xdef s(self,x,y): return self.f(x) == self.f(y)w,h = map(int,input().split())mod = 998244353; uf = UF(w+10); c = wfor _ in range(h):s = [[] for _ in range(26)]for i,v in enumerate(input()):a = ord(v)if 48<=a<=57 and not uf.s(i,w+a-48): uf.u(i,w+a-48); c -= 1if 97<=a<=122: s[a-97].append(i)for t in s:for u,v in zip(t[:-1],t[1:]):if not uf.s(u,v): uf.u(u,v); c -= 1if len(set(uf.f(w+i) for i in range(10)))<10: c = -1print(pow(10,c,mod) if c>=0 else 0)