結果

問題 No.2428 Returning Shuffle
ユーザー ntudantuda
提出日時 2023-08-19 10:55:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 907 ms / 2,000 ms
コード長 1,362 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 233,148 KB
最終ジャッジ日時 2023-08-19 10:55:48
合計ジャッジ時間 8,210 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
95,716 KB
testcase_01 AC 871 ms
98,652 KB
testcase_02 AC 907 ms
97,584 KB
testcase_03 AC 79 ms
71,348 KB
testcase_04 AC 78 ms
71,620 KB
testcase_05 AC 79 ms
71,440 KB
testcase_06 AC 79 ms
71,468 KB
testcase_07 AC 82 ms
71,332 KB
testcase_08 AC 83 ms
71,620 KB
testcase_09 AC 81 ms
71,520 KB
testcase_10 AC 78 ms
71,440 KB
testcase_11 AC 79 ms
71,652 KB
testcase_12 AC 81 ms
71,472 KB
testcase_13 AC 95 ms
71,476 KB
testcase_14 AC 80 ms
71,624 KB
testcase_15 AC 81 ms
71,620 KB
testcase_16 AC 80 ms
71,728 KB
testcase_17 AC 80 ms
71,512 KB
testcase_18 AC 83 ms
71,328 KB
testcase_19 AC 577 ms
97,136 KB
testcase_20 AC 581 ms
98,464 KB
testcase_21 AC 81 ms
71,520 KB
testcase_22 AC 78 ms
71,324 KB
testcase_23 AC 80 ms
71,320 KB
testcase_24 AC 571 ms
233,148 KB
testcase_25 AC 566 ms
232,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)

0