結果
問題 | No.2291 Union Find Estimate |
ユーザー | とりゐ |
提出日時 | 2023-05-05 21:43:51 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 313 ms / 2,000 ms |
コード長 | 1,710 bytes |
コンパイル時間 | 1,281 ms |
コンパイル使用メモリ | 87,196 KB |
実行使用メモリ | 93,092 KB |
最終ジャッジ日時 | 2023-08-15 03:28:34 |
合計ジャッジ時間 | 4,954 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 96 ms
71,428 KB |
testcase_01 | AC | 97 ms
71,788 KB |
testcase_02 | AC | 313 ms
81,432 KB |
testcase_03 | AC | 140 ms
93,092 KB |
testcase_04 | AC | 104 ms
76,244 KB |
testcase_05 | AC | 101 ms
72,148 KB |
testcase_06 | AC | 99 ms
72,356 KB |
testcase_07 | AC | 101 ms
76,484 KB |
testcase_08 | AC | 120 ms
77,744 KB |
testcase_09 | AC | 121 ms
77,856 KB |
testcase_10 | AC | 175 ms
78,848 KB |
testcase_11 | AC | 203 ms
79,460 KB |
testcase_12 | AC | 225 ms
79,264 KB |
testcase_13 | AC | 135 ms
84,588 KB |
testcase_14 | AC | 146 ms
78,248 KB |
testcase_15 | AC | 147 ms
80,596 KB |
testcase_16 | AC | 152 ms
78,452 KB |
testcase_17 | AC | 139 ms
78,852 KB |
testcase_18 | AC | 135 ms
78,600 KB |
testcase_19 | AC | 162 ms
78,596 KB |
ソースコード
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: print(0) 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: c=uf.grp_cnt-10 print(pow(10,c,mod))