結果

問題 No.2428 Returning Shuffle
ユーザー sotanishysotanishy
提出日時 2023-08-18 21:50:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 779 ms / 2,000 ms
コード長 1,229 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 268,912 KB
最終ジャッジ日時 2023-08-18 21:51:11
合計ジャッジ時間 8,528 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
104,528 KB
testcase_01 AC 745 ms
102,616 KB
testcase_02 AC 779 ms
102,656 KB
testcase_03 AC 93 ms
71,588 KB
testcase_04 AC 91 ms
71,448 KB
testcase_05 AC 95 ms
71,584 KB
testcase_06 AC 97 ms
71,532 KB
testcase_07 AC 102 ms
71,688 KB
testcase_08 AC 95 ms
71,732 KB
testcase_09 AC 95 ms
71,648 KB
testcase_10 AC 94 ms
71,564 KB
testcase_11 AC 95 ms
71,512 KB
testcase_12 AC 96 ms
71,712 KB
testcase_13 AC 91 ms
71,672 KB
testcase_14 AC 93 ms
71,668 KB
testcase_15 AC 95 ms
71,768 KB
testcase_16 AC 92 ms
71,568 KB
testcase_17 AC 103 ms
71,704 KB
testcase_18 AC 95 ms
71,448 KB
testcase_19 AC 483 ms
102,192 KB
testcase_20 AC 485 ms
102,324 KB
testcase_21 AC 127 ms
71,728 KB
testcase_22 AC 97 ms
71,392 KB
testcase_23 AC 98 ms
71,556 KB
testcase_24 AC 646 ms
268,860 KB
testcase_25 AC 705 ms
268,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict
import sys
input = sys.stdin.readline


def prime_factor(n):
    factors = {}
    if n % 2 == 0:
        cnt = 0
        while n % 2 == 0:
            cnt += 1
            n //= 2
        factors[2] = cnt
    i = 3
    while i * i <= n:
        if n % i == 0:
            cnt = 0
            while n % i == 0:
                cnt += 1
                n //= i
            factors[i] = cnt
        i += 2
    if n != 1:
        factors[n] = 1
    return factors


mod = 998244353
N, M = map(int, input().split())
P = list(range(N))
Q = list(range(N))
for _ in range(M):
    T, *S = map(int, input().split())
    S = list(map(lambda x: x-1, S))
    tmp = Q[P[S[0]]]
    x = [P[S[0]]]
    for i in range(T-1):
        Q[P[S[i]]] = Q[P[S[i+1]]]
        x.append(P[S[i+1]])
    Q[P[S[T-1]]] = tmp

    for i in x:
        P[Q[i]] = i

visited = [0] * N
exp = defaultdict(int)
for i in P:
    if visited[i]:
        continue
    j = P[i]
    cnt = 1
    visited[j] = 1
    while j != i:
        j = P[j]
        cnt += 1
        visited[j] = 1
    for p, c in prime_factor(cnt).items():
        exp[p] = max(exp[p], c)
ans = 1
for p, e in exp.items():
    ans = ans * pow(p, e, mod) % mod
print(ans)
0