結果
問題 | No.2291 Union Find Estimate |
ユーザー | neterukun |
提出日時 | 2023-05-05 22:07:27 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,583 bytes |
コンパイル時間 | 233 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 130,780 KB |
最終ジャッジ日時 | 2024-05-02 16:27:40 |
合計ジャッジ時間 | 3,110 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
52,352 KB |
testcase_01 | AC | 35 ms
52,480 KB |
testcase_02 | AC | 167 ms
84,480 KB |
testcase_03 | AC | 181 ms
130,780 KB |
testcase_04 | AC | 87 ms
76,416 KB |
testcase_05 | AC | 85 ms
76,288 KB |
testcase_06 | AC | 78 ms
76,288 KB |
testcase_07 | AC | 75 ms
73,216 KB |
testcase_08 | AC | 80 ms
76,288 KB |
testcase_09 | AC | 76 ms
76,416 KB |
testcase_10 | AC | 92 ms
76,928 KB |
testcase_11 | AC | 99 ms
77,440 KB |
testcase_12 | AC | 117 ms
78,208 KB |
testcase_13 | AC | 91 ms
88,960 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | AC | 92 ms
76,800 KB |
ソースコード
class UnionFind: def __init__(self, n): self.parent = [-1] * n self.n = n self.cnt = n def root(self, x): if self.parent[x] < 0: return x else: self.parent[x] = self.root(self.parent[x]) return self.parent[x] def merge(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.parent[x] > self.parent[y]: x, y = y, x self.parent[x] += self.parent[y] self.parent[y] = x self.cnt -= 1 for yy in groups[y]: groups[x].append(yy) del groups[y] return True def same(self, x, y): return self.root(x) == self.root(y) def size(self, x): return -self.parent[self.root(x)] def count(self): return self.cnt def groups(self): res = [[] for _ in range(self.n)] for i in range(self.n): res[self.root(i)].append(i) return [group for group in res if group] w, h = map(int, input().split()) queries = [input() for _ in range(h)] MOD = 998244353 inv10 = pow(10, MOD - 2, MOD) ptn = pow(10, w, MOD) uf = UnionFind(w) groups = {} for i in range(w): groups[i] = [i] numbers = {} for i in range(w): numbers[i] = -1 for query in queries: before = [-1] * 26 for i, char in enumerate(query): if char == "?": continue if char in '0123456789': rt = uf.root(i) if numbers[rt] == -1: numbers[rt] = int(char) ptn *= inv10 ptn %= MOD elif numbers[rt] != int(char): ptn = 0 else: val = ord(char) - 97 if before[val] == -1: before[val] = uf.root(i) else: rt = uf.root(i) if rt == before[val]: continue if numbers[rt] == -1 and numbers[before[val]] == -1: ptn *= inv10 ptn %= MOD elif numbers[rt] == -1: ptn *= inv10 ptn %= MOD numbers[rt] = numbers[before[val]] elif numbers[before[val]] == -1: ptn *= inv10 ptn %= MOD numbers[before[val]] = numbers[rt] elif numbers[rt] != numbers[before[val]]: ptn = 0 uf.merge(before[val], rt) before[val] = uf.root(i) print(ptn)