結果
問題 |
No.2291 Union Find Estimate
|
ユーザー |
![]() |
提出日時 | 2023-05-06 18:29:26 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 523 ms / 2,000 ms |
コード長 | 1,629 bytes |
コンパイル時間 | 143 ms |
コンパイル使用メモリ | 82,120 KB |
実行使用メモリ | 82,048 KB |
最終ジャッジ日時 | 2024-11-24 01:00:17 |
合計ジャッジ時間 | 3,241 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
MOD = 998244353 W,H = map(int,input().split()) P = [-1] * W def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x,y): x = root(x) y = root(y) if x == y: return if x > y: x,y = y,x P[x] += P[y] P[y] = x if y in code and x not in code: code[x] = code[y] code.pop(y) elif x in code and y in code: if code[x] == code[y]: code.pop(y) else: return False return True def same(x,y): return root(x) == root(y) from collections import defaultdict code = {} flag = 1 for h in range(H): if flag == 0: print(0) continue S = input() dic = defaultdict(list) for i in range(W): ri = root(i) s = S[i] x = ord(s) if 48 <= x <= 57: x -= 48 if ri in code: if code[ri] != x: flag = 0 print(0) break else: code[ri] = x if 97 <= x <= 122: dic[s].append(i) #print(i,P,code,flag) if flag == 1: for _,V in dic.items(): if len(V) > 1: v0 = V[0] for v in V[1:]: if unite(v0,v) == False: flag = 0 print(0) break if flag == 0: break if flag == 1: cnt = 0 ans = 1 for i in range(W): if P[i] < 0 and i not in code: cnt += 1 print(pow(10,cnt,MOD))