結果
問題 | No.2045 Two Reflections |
ユーザー | 👑 rin204 |
提出日時 | 2022-08-19 22:29:13 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 104 ms / 2,000 ms |
コード長 | 1,855 bytes |
コンパイル時間 | 298 ms |
コンパイル使用メモリ | 82,328 KB |
実行使用メモリ | 79,124 KB |
最終ジャッジ日時 | 2024-10-08 09:28:02 |
合計ジャッジ時間 | 3,188 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,224 KB |
testcase_01 | AC | 45 ms
52,608 KB |
testcase_02 | AC | 63 ms
65,920 KB |
testcase_03 | AC | 85 ms
76,800 KB |
testcase_04 | AC | 86 ms
78,336 KB |
testcase_05 | AC | 42 ms
52,956 KB |
testcase_06 | AC | 43 ms
52,992 KB |
testcase_07 | AC | 92 ms
78,848 KB |
testcase_08 | AC | 104 ms
79,124 KB |
testcase_09 | AC | 47 ms
52,608 KB |
testcase_10 | AC | 43 ms
52,736 KB |
testcase_11 | AC | 83 ms
73,344 KB |
testcase_12 | AC | 42 ms
52,608 KB |
testcase_13 | AC | 46 ms
52,480 KB |
testcase_14 | AC | 48 ms
52,864 KB |
testcase_15 | AC | 43 ms
52,608 KB |
testcase_16 | AC | 41 ms
52,352 KB |
testcase_17 | AC | 40 ms
52,480 KB |
testcase_18 | AC | 42 ms
52,736 KB |
testcase_19 | AC | 40 ms
52,736 KB |
testcase_20 | AC | 41 ms
52,352 KB |
testcase_21 | AC | 60 ms
66,176 KB |
testcase_22 | AC | 64 ms
66,432 KB |
testcase_23 | AC | 61 ms
66,432 KB |
testcase_24 | AC | 60 ms
66,688 KB |
testcase_25 | AC | 60 ms
66,560 KB |
testcase_26 | AC | 61 ms
66,048 KB |
testcase_27 | AC | 61 ms
66,560 KB |
testcase_28 | AC | 63 ms
65,792 KB |
testcase_29 | AC | 63 ms
66,304 KB |
ソースコード
from math import gcd MOD = 998244353 class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n self.group = 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 self.group -= 1 if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x 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 self.group def all_group_members(self): dic = {r:[] for r in self.roots()} for i in range(self.n): dic[self.find(i)].append(i) return dic def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) n, p, q = map(int, input().split()) if p == 1 and q == 1: ans = 1 elif p == 1 or q == 1: ans = 2 elif p + q <= n: ans = 4 elif p == q == n: ans = 2 else: A = [i for i in range(n)] B = A[:] for i in range(p): B[i] = A[p - 1 - i] A = B[:] for i in range(n - q, n): B[i] = A[2 * n - 1 - q - i] UF = UnionFind(n) for i, b in enumerate(B): UF.union(i, b) ans = 1 for r in UF.roots(): s = UF.size(r) ans = ans * s // gcd(ans, s) ans *= 2 ans %= MOD print(ans)