結果

問題 No.2428 Returning Shuffle
ユーザー Nikkuniku029Nikkuniku029
提出日時 2023-08-18 22:32:23
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 658 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 266,780 KB
最終ジャッジ日時 2024-05-06 04:51:31
合計ジャッジ時間 5,463 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 35 ms
52,736 KB
testcase_04 AC 35 ms
52,096 KB
testcase_05 AC 35 ms
52,352 KB
testcase_06 AC 35 ms
52,096 KB
testcase_07 AC 35 ms
52,352 KB
testcase_08 AC 35 ms
52,352 KB
testcase_09 AC 34 ms
52,096 KB
testcase_10 AC 35 ms
52,352 KB
testcase_11 AC 35 ms
52,608 KB
testcase_12 AC 35 ms
52,736 KB
testcase_13 AC 36 ms
52,352 KB
testcase_14 AC 37 ms
52,608 KB
testcase_15 AC 36 ms
52,608 KB
testcase_16 AC 36 ms
51,968 KB
testcase_17 AC 36 ms
52,096 KB
testcase_18 AC 36 ms
52,608 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 35 ms
51,968 KB
testcase_22 AC 36 ms
52,608 KB
testcase_23 AC 36 ms
52,224 KB
testcase_24 AC 408 ms
266,780 KB
testcase_25 AC 426 ms
266,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
N, M = map(int, input().split())
P = [i for i in range(N)]
for _ in range(M):
    L, *T = list(map(int, input().split()))
    sigma = []
    for t in T:
        sigma.append(P[t-1])
    for i in range(L):
        if i < L-1:
            j = T[i+1]-1
        else:
            j = T[0]-1
        P[j] = sigma[i]
loop = []
seen = [False]*N
for i in range(N):
    if seen[i]:
        continue
    tmp = 1
    seen[i] = True
    next = P[i]
    while not seen[next]:
        seen[next] = True
        tmp += 1
        next = P[next]
    loop.append(tmp)
ans = 1
MOD = 998244353
for c in loop:
    ans = (ans*c//gcd(ans, c)) % MOD
print(ans)
0