結果

問題 No.2291 Union Find Estimate
ユーザー とりゐとりゐ
提出日時 2023-05-05 21:42:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,722 bytes
コンパイル時間 472 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 99,532 KB
最終ジャッジ日時 2024-05-02 15:40:39
合計ジャッジ時間 3,497 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
54,272 KB
testcase_01 AC 45 ms
54,272 KB
testcase_02 AC 346 ms
83,456 KB
testcase_03 AC 95 ms
92,736 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 156 ms
77,696 KB
testcase_11 AC 175 ms
78,452 KB
testcase_12 AC 203 ms
78,592 KB
testcase_13 AC 135 ms
99,532 KB
testcase_14 AC 120 ms
76,672 KB
testcase_15 AC 106 ms
86,016 KB
testcase_16 AC 106 ms
77,248 KB
testcase_17 AC 119 ms
84,992 KB
testcase_18 AC 120 ms
85,248 KB
testcase_19 AC 153 ms
77,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]

from collections import defaultdict

class UnionFind():
  def __init__(self,n):
    self.n=n
    self.parents=[-1]*n
    self.grp_cnt=n

  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]

  def union(self,x,y):
    x=self.find(x)
    y=self.find(y)

    if x==y:
      return

    if self.parents[x]>self.parents[y]:
      x,y=y,x

    self.parents[x]+=self.parents[y]
    self.parents[y]=x
    self.grp_cnt-=1

  def size(self,x):
    return -self.parents[self.find(x)]

  def same(self,x,y):
    return self.find(x)==self.find(y)

  def members(self,x):
    root=self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i, x in enumerate(self.parents) if x< 0]

  def group_count(self):
    return len(self.roots())

  def all_group_members(self):
    group_members=defaultdict(list)
    for member in range(self.n):
      group_members[self.find(member)].append(member)
    return group_members

mod=998244353
w,h=map(int,input().split())
uf=UnionFind(w+10)
flag=False
from collections import defaultdict
for _ in range(h):
  s=input()
  if flag:
    continue
  d=defaultdict(list)
  for i in range(w):
    d[s[i]].append(i)
  
  for j in d:
    if '0'<=j<='9':
      for i in d[j]:
        uf.union(i,w+int(j))
    else:
      if j=='?':
        continue
      for i in d[j]:
        uf.union(d[j][0],i)
  
  for i in range(10):
    for j in range(i+1,10):
      if uf.same(w+i,w+j):
        flag=True
  
  if flag:
    print(0)
  else:
    g=uf.all_group_members()
    c=len(g)-10
    print(pow(10,c,mod))
0