結果

問題 No.2428 Returning Shuffle
ユーザー 👑 tatyam
提出日時 2023-08-18 21:47:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 580 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 247,860 KB
最終ジャッジ日時 2024-11-28 06:28:11
合計ジャッジ時間 5,763 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from math import lcm
from collections import deque
input = sys.stdin.readline

N, M = map(int, input().split())
P = list(range(N))

for _ in range(M):
    T, *S = map(int, input().split())
    S.reverse()
    for i, j in zip(S, S[1:]):
        i -= 1
        j -= 1
        P[i], P[j] = P[j], P[i]

cycle = deque()
visited = [False] * N

for i in range(N):
    if visited[i]:
        continue
    L = 0
    while not visited[i]:
        visited[i] = True
        i = P[i]
        L += 1
    cycle.append(L)

while len(cycle) >= 2:
    x = cycle.popleft()
    y = cycle.popleft()
    cycle.append(lcm(x, y))

print(cycle[0] % 998244353)
0