結果
問題 | No.2291 Union Find Estimate |
ユーザー | qib |
提出日時 | 2023-05-06 04:04:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,076 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 95,528 KB |
最終ジャッジ日時 | 2024-11-23 15:28:30 |
合計ジャッジ時間 | 3,981 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,864 KB |
testcase_01 | WA | - |
testcase_02 | AC | 521 ms
77,440 KB |
testcase_03 | AC | 126 ms
79,488 KB |
testcase_04 | AC | 55 ms
62,848 KB |
testcase_05 | AC | 57 ms
62,720 KB |
testcase_06 | AC | 48 ms
55,808 KB |
testcase_07 | AC | 45 ms
54,272 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | AC | 160 ms
77,080 KB |
testcase_11 | AC | 178 ms
76,900 KB |
testcase_12 | AC | 229 ms
77,312 KB |
testcase_13 | AC | 127 ms
95,528 KB |
testcase_14 | AC | 211 ms
77,008 KB |
testcase_15 | AC | 181 ms
78,212 KB |
testcase_16 | AC | 222 ms
77,152 KB |
testcase_17 | AC | 124 ms
79,100 KB |
testcase_18 | AC | 122 ms
79,216 KB |
testcase_19 | AC | 157 ms
77,512 KB |
ソースコード
MOD = 998244353 class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def root(self, v): if self.node[v] < 0: return v st = [] while self.node[v] >= 0: st.append(v) v = self.node[v] for u in st: self.node[u] = v return v def size(self, v): v = self.root(v) return (- self.node[v]) def same(self, u, v): return self.root(u) == self.root(v) def unite(self, u, v): ru = self.root(u) rv = self.root(v) if ru == rv: return du = self.node[ru] dv = self.node[rv] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du w, h = map(int, input().split()) uf = UnionFind(w) num = [None for _ in range(w)] flg = True for _ in range(h): qi = input() ans = 1 if not flg: ans = 0 idx = {} for j in range(w * ans): if qi[j] == "?": continue elif ord("a") <= ord(qi[j]) <= ord("z"): if idx.get(qi[j], None) is None: idx[qi[j]] = j else: uf.unite(idx[qi[j]], j) r = uf.root(j) none_r = num[r] is None none_j = num[j] is None if not none_r and not none_j: if num[r] != num[j]: flg = False ans = 0 break elif none_r and not none_j: num[r] = num[j] elif none_j and not none_r: num[j] = num[r] else: if num[j] is None: num[j] = int(qi[j]) elif num[j] != int(qi[j]): flg = False ans = 0 break par = {} for v in range(w * ans): r = uf.root(v) none_r = num[r] is None none_v = num[v] is None if not none_r and not none_v: if num[r] != num[v]: flg = False ans = 0 break elif none_r and not none_v: num[r] = num[v] elif none_v and not none_r: num[v] = num[r] if par.get(r, None) is None: par[r] = num[r] for k, v in par.items(): if v is None: ans = (ans * 10) % MOD print(ans)