結果

問題 No.2428 Returning Shuffle
ユーザー rlangevinrlangevin
提出日時 2023-09-18 15:14:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,401 ms / 2,000 ms
コード長 1,451 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 276,196 KB
最終ジャッジ日時 2023-09-18 15:14:17
合計ジャッジ時間 11,117 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 333 ms
111,380 KB
testcase_01 AC 1,088 ms
157,448 KB
testcase_02 AC 1,083 ms
157,328 KB
testcase_03 AC 75 ms
71,252 KB
testcase_04 AC 76 ms
71,176 KB
testcase_05 AC 74 ms
71,492 KB
testcase_06 AC 77 ms
71,560 KB
testcase_07 AC 75 ms
71,448 KB
testcase_08 AC 75 ms
71,488 KB
testcase_09 AC 77 ms
71,172 KB
testcase_10 AC 76 ms
71,240 KB
testcase_11 AC 76 ms
71,312 KB
testcase_12 AC 74 ms
71,392 KB
testcase_13 AC 76 ms
70,916 KB
testcase_14 AC 78 ms
71,096 KB
testcase_15 AC 75 ms
71,512 KB
testcase_16 AC 76 ms
71,236 KB
testcase_17 AC 77 ms
71,252 KB
testcase_18 AC 77 ms
71,044 KB
testcase_19 AC 1,142 ms
170,004 KB
testcase_20 AC 1,138 ms
170,020 KB
testcase_21 AC 76 ms
71,288 KB
testcase_22 AC 75 ms
71,320 KB
testcase_23 AC 72 ms
71,360 KB
testcase_24 AC 1,171 ms
275,944 KB
testcase_25 AC 1,401 ms
276,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def rot(P, T):
    M = T.pop(0)
    temp = dict()
    for i in range(M):
        temp[T[(i + 1)%M] - 1] = P[T[i] - 1]
    for k, v in temp.items():
        P[k] = v
    return P


class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        x = self.find(x)
        return self.size[x]



N, M = map(int, input().split())
mod = 998244353
P = list(range(N))
for _ in range(M):
    S = list(map(int, input().split()))
    P = rot(P, S)
    
U = UnionFind(N)
for i in range(N):
    U.union(i, P[i])
    
SS = set()
from math import gcd
ans = 1
for i in range(N):
    if U.find(i) in SS:
        continue
    SS.add(U.find(i))
    ans = (ans * U.get_size(i))//gcd(ans, U.get_size(i))
    
print(ans%mod)
0