結果
問題 | No.2291 Union Find Estimate |
ユーザー |
![]() |
提出日時 | 2023-05-05 21:56:32 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,421 bytes |
コンパイル時間 | 760 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 22,144 KB |
最終ジャッジ日時 | 2024-11-23 07:24:20 |
合計ジャッジ時間 | 11,540 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 12 |
ソースコード
import syssys.setrecursionlimit(500000)class UF:def __init__(self, n):self.root = [i for i in range(n)]self.subt = [1] * ndef find(self, x):if self.root[x] == x:return xelse:self.root[x] = self.find(self.root[x])return self.root[x]def union(self, x, y):x, y = self.find(x), self.find(y)x, y = min(x, y), max(x, y)if x != y:self.subt[x] += self.subt[y]self.root[y] = xdef size(self, x):return self.subt[self.find(x)]w, h = map(int, input().split())uf = UF(w)mod = 998244353ans = pow(10, w, mod)flg = [0] * wfor i in range(h):q = input()root = dict()for j in range(w):if "0" <= q[j] <= "9":if flg[uf.find(j)]:if flg[uf.find(j)] != q[j]:ans = 0continueflg[uf.find(j)] = q[j]ans *= pow(10, mod-2, mod)ans %= modelif "a" <= q[j] <= "z":if q[j] not in root:root[q[j]] = jelse:if flg[uf.find(root[q[j]])] and flg[uf.find(j)] and flg[uf.find(root[q[j]])] != flg[uf.find(j)]:ans = 0if uf.find(root[q[j]]) != uf.find(j) and not flg[uf.find(root[q[j]])] or not flg[uf.find(j)]:ans *= pow(10, mod-2, mod)ans %= moduf.union(root[q[j]], j)if flg[j]:flg[uf.find(j)] = flg[j]if flg[root[q[j]]]:flg[uf.find(j)] = flg[root[q[j]]]print(ans)