結果

問題 No.2428 Returning Shuffle
ユーザー rlangevinrlangevin
提出日時 2023-09-18 15:12:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,431 bytes
コンパイル時間 866 ms
コンパイル使用メモリ 86,716 KB
実行使用メモリ 275,520 KB
最終ジャッジ日時 2023-09-18 15:12:25
合計ジャッジ時間 13,332 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 75 ms
70,984 KB
testcase_04 AC 74 ms
70,960 KB
testcase_05 AC 72 ms
71,340 KB
testcase_06 AC 72 ms
71,096 KB
testcase_07 AC 74 ms
71,304 KB
testcase_08 AC 75 ms
71,428 KB
testcase_09 AC 77 ms
71,016 KB
testcase_10 AC 74 ms
71,348 KB
testcase_11 AC 72 ms
71,340 KB
testcase_12 AC 77 ms
71,128 KB
testcase_13 AC 75 ms
71,212 KB
testcase_14 AC 75 ms
71,160 KB
testcase_15 AC 75 ms
71,252 KB
testcase_16 AC 76 ms
71,432 KB
testcase_17 AC 76 ms
71,132 KB
testcase_18 AC 78 ms
71,340 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 75 ms
71,248 KB
testcase_22 AC 74 ms
71,104 KB
testcase_23 AC 76 ms
71,268 KB
testcase_24 AC 1,288 ms
274,844 KB
testcase_25 AC 1,435 ms
275,520 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())
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)
0