結果

問題 No.2428 Returning Shuffle
ユーザー rlangevinrlangevin
提出日時 2023-09-18 15:12:58
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,462 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 87,052 KB
実行使用メモリ 276,580 KB
最終ジャッジ日時 2023-09-18 15:13:26
合計ジャッジ時間 10,978 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 76 ms
71,112 KB
testcase_04 AC 74 ms
71,376 KB
testcase_05 AC 74 ms
71,176 KB
testcase_06 AC 72 ms
71,176 KB
testcase_07 AC 74 ms
71,228 KB
testcase_08 AC 74 ms
71,184 KB
testcase_09 AC 72 ms
71,264 KB
testcase_10 AC 73 ms
71,420 KB
testcase_11 AC 72 ms
71,304 KB
testcase_12 AC 72 ms
71,260 KB
testcase_13 AC 75 ms
71,232 KB
testcase_14 AC 73 ms
71,060 KB
testcase_15 AC 73 ms
71,252 KB
testcase_16 AC 72 ms
71,348 KB
testcase_17 AC 73 ms
71,064 KB
testcase_18 AC 71 ms
71,180 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 72 ms
71,112 KB
testcase_22 AC 72 ms
71,244 KB
testcase_23 AC 72 ms
71,060 KB
testcase_24 AC 1,205 ms
276,580 KB
testcase_25 AC 1,191 ms
275,656 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))
    ans %= mod
    
print(ans)
0