結果
問題 | 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 = 998244353import collectionsdef prime_factorize(n):a = []while n % 2 == 0:a.append(2)n //= 2f = 3while f * f <= n:if n % f == 0:a.append(f)n //= felse:f += 2if n != 1:a.append(n)return adef n_fact(N):c = collections.Counter(prime_factorize(N))return cdef root(x):if P[x] < 0: return xP[x] = root(P[x]) # 経路圧縮return P[x]def unite(x, y):x = root(x)y = root(y)if x == y: returnif x > y: x, y = y, xP[x] += P[y]P[y] = xdef 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] * NP1 = 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] = s0continueP1[S[(i + 1) % t] - 1] = P1[S[i] - 1]for i, p in enumerate(P1):unite(i, p)from collections import defaultdictdic = 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 = 1for k,v in dic.items():ans *= pow(k,v,MOD)ans %= MODprint(ans)