結果
問題 |
No.2428 Returning Shuffle
|
ユーザー |
![]() |
提出日時 | 2023-08-19 10:55:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 981 ms / 2,000 ms |
コード長 | 1,362 bytes |
コンパイル時間 | 396 ms |
コンパイル使用メモリ | 82,180 KB |
実行使用メモリ | 253,488 KB |
最終ジャッジ日時 | 2024-11-29 02:43:50 |
合計ジャッジ時間 | 7,622 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
MOD = 998244353 import collections def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a def n_fact(N): c = collections.Counter(prime_factorize(N)) return c def root(x): if P[x] < 0: return x P[x] = root(P[x]) # 経路圧縮 return P[x] def unite(x, y): x = root(x) y = root(y) if x == y: return if x > y: x, y = y, x P[x] += P[y] P[y] = x def same(x, y): return root(x) == root(y) def size(x): x = root(x) return -P[x] N, M = map(int, input().split()) P = [-1] * N P1 = list(range(N)) for _ in range(M): t, *S = map(int, input().split()) s0 = P1[S[0] - 1] n = len(S) for i in reversed(range(n)): if i == 0: P1[S[(i + 1) % t] - 1] = s0 continue P1[S[(i + 1) % t] - 1] = P1[S[i] - 1] for i, p in enumerate(P1): unite(i, p) from collections import defaultdict dic = defaultdict(int) for i in range(N): if i == root(i): s = size(i) p = n_fact(s) for k,v in p.items(): dic[k] = max(dic[k],p[k]) ans = 1 for k,v in dic.items(): ans *= pow(k,v,MOD) ans %= MOD print(ans)