結果
| 問題 |
No.2291 Union Find Estimate
|
| コンテスト | |
| ユーザー |
ニックネーム
|
| 提出日時 | 2023-05-05 21:51:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 708 ms / 2,000 ms |
| コード長 | 878 bytes |
| コンパイル時間 | 299 ms |
| コンパイル使用メモリ | 82,328 KB |
| 実行使用メモリ | 84,096 KB |
| 最終ジャッジ日時 | 2024-11-23 07:02:26 |
| 合計ジャッジ時間 | 4,267 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
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 s(self,x,y): return self.f(x) == self.f(y)
w,h = map(int,input().split())
mod = 998244353; uf = UF(w+10); c = w
for _ 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 -= 1
if 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 -= 1
if len(set(uf.f(w+i) for i in range(10)))<10: c = -1
print(pow(10,c,mod) if c>=0 else 0)
ニックネーム