結果
| 問題 |
No.2428 Returning Shuffle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-18 22:35:28 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 616 bytes |
| コンパイル時間 | 490 ms |
| コンパイル使用メモリ | 81,408 KB |
| 実行使用メモリ | 266,672 KB |
| 最終ジャッジ日時 | 2024-11-28 08:36:22 |
| 合計ジャッジ時間 | 5,396 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 5 |
ソースコード
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]
seen = [False]*N
ans = 1
MOD = 998244353
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]
ans = (ans*tmp//gcd(ans, tmp)) % MOD
print(ans)