結果

問題 No.2428 Returning Shuffle
ユーザー 👑 tatyamtatyam
提出日時 2023-08-18 21:47:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 247,988 KB
最終ジャッジ日時 2024-05-06 03:45:22
合計ジャッジ時間 5,408 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 180 ms
93,952 KB
testcase_01 AC 488 ms
104,808 KB
testcase_02 AC 510 ms
105,400 KB
testcase_03 AC 39 ms
53,888 KB
testcase_04 AC 39 ms
53,504 KB
testcase_05 AC 38 ms
54,144 KB
testcase_06 AC 38 ms
53,376 KB
testcase_07 AC 37 ms
53,760 KB
testcase_08 AC 38 ms
54,144 KB
testcase_09 AC 37 ms
54,144 KB
testcase_10 AC 41 ms
54,016 KB
testcase_11 AC 38 ms
53,888 KB
testcase_12 AC 38 ms
53,760 KB
testcase_13 AC 38 ms
53,760 KB
testcase_14 AC 38 ms
54,144 KB
testcase_15 AC 39 ms
53,888 KB
testcase_16 AC 37 ms
53,760 KB
testcase_17 AC 38 ms
54,144 KB
testcase_18 AC 39 ms
53,888 KB
testcase_19 AC 301 ms
101,632 KB
testcase_20 AC 281 ms
101,184 KB
testcase_21 AC 40 ms
53,888 KB
testcase_22 AC 40 ms
54,144 KB
testcase_23 AC 39 ms
53,632 KB
testcase_24 AC 406 ms
247,988 KB
testcase_25 AC 395 ms
247,604 KB
権限があれば一括ダウンロードができます

ソースコード

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