結果

問題 No.2428 Returning Shuffle
ユーザー 👑 tatyamtatyam
提出日時 2023-08-18 21:47:25
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 639 ms / 2,000 ms
コード長 647 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 226,896 KB
最終ジャッジ日時 2023-08-18 21:47:33
合計ジャッジ時間 7,432 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 259 ms
95,208 KB
testcase_01 AC 616 ms
105,796 KB
testcase_02 AC 639 ms
106,672 KB
testcase_03 AC 93 ms
71,812 KB
testcase_04 AC 92 ms
71,600 KB
testcase_05 AC 92 ms
71,724 KB
testcase_06 AC 92 ms
71,612 KB
testcase_07 AC 95 ms
71,744 KB
testcase_08 AC 92 ms
71,468 KB
testcase_09 AC 92 ms
71,744 KB
testcase_10 AC 91 ms
71,968 KB
testcase_11 AC 92 ms
72,068 KB
testcase_12 AC 99 ms
71,572 KB
testcase_13 AC 97 ms
71,576 KB
testcase_14 AC 92 ms
71,424 KB
testcase_15 AC 90 ms
71,736 KB
testcase_16 AC 92 ms
71,924 KB
testcase_17 AC 93 ms
71,400 KB
testcase_18 AC 96 ms
71,672 KB
testcase_19 AC 410 ms
100,916 KB
testcase_20 AC 397 ms
101,460 KB
testcase_21 AC 94 ms
71,960 KB
testcase_22 AC 96 ms
71,736 KB
testcase_23 AC 99 ms
71,744 KB
testcase_24 AC 507 ms
226,732 KB
testcase_25 AC 457 ms
226,896 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