結果

問題 No.2291 Union Find Estimate
ユーザー ntuda
提出日時 2023-05-06 16:50:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,541 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 82,176 KB
最終ジャッジ日時 2024-11-23 23:51:23
合計ジャッジ時間 3,748 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

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 _ 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)
continue
else:
code[ri] = x
if 97 <= x <= 122:
dic[s].append(i)
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)
continue
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))
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0