結果
問題 | No.1917 LCMST |
ユーザー | qib |
提出日時 | 2023-05-06 04:13:15 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,068 bytes |
コンパイル時間 | 360 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 65,920 KB |
最終ジャッジ日時 | 2024-05-02 21:01:31 |
合計ジャッジ時間 | 9,237 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
ソースコード
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)