結果

問題 No.2428 Returning Shuffle
ユーザー ShirotsumeShirotsume
提出日時 2023-08-18 21:32:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,244 ms / 2,000 ms
コード長 2,570 bytes
コンパイル時間 426 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 335,480 KB
最終ジャッジ日時 2024-05-06 03:25:24
合計ジャッジ時間 8,856 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 338 ms
161,808 KB
testcase_01 AC 1,244 ms
276,136 KB
testcase_02 AC 1,234 ms
276,220 KB
testcase_03 AC 45 ms
55,808 KB
testcase_04 AC 46 ms
55,808 KB
testcase_05 AC 48 ms
55,808 KB
testcase_06 AC 48 ms
55,936 KB
testcase_07 AC 46 ms
55,680 KB
testcase_08 AC 43 ms
55,936 KB
testcase_09 AC 44 ms
55,808 KB
testcase_10 AC 44 ms
56,064 KB
testcase_11 AC 45 ms
55,936 KB
testcase_12 AC 46 ms
55,936 KB
testcase_13 AC 46 ms
55,808 KB
testcase_14 AC 46 ms
55,808 KB
testcase_15 AC 46 ms
55,680 KB
testcase_16 AC 45 ms
55,936 KB
testcase_17 AC 44 ms
55,936 KB
testcase_18 AC 46 ms
55,936 KB
testcase_19 AC 712 ms
233,776 KB
testcase_20 AC 737 ms
230,536 KB
testcase_21 AC 46 ms
55,808 KB
testcase_22 AC 47 ms
56,064 KB
testcase_23 AC 47 ms
55,680 KB
testcase_24 AC 839 ms
327,288 KB
testcase_25 AC 932 ms
335,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, time, random
from collections import deque, Counter, defaultdict
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
class dsu():
    n=1
    parent_or_size=[-1 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.num = N
        self.parent_or_size=[-1 for i in range(N)]
    def merge(self,a,b):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n)
        x=self.leader(a)
        y=self.leader(b)
        if x==y:
            return x
        self.num -= 1
        if (-self.parent_or_size[x]<-self.parent_or_size[y]):
            x,y=y,x
        self.parent_or_size[x]+=self.parent_or_size[y]
        self.parent_or_size[y]=x
        return x
    def same(self,a,b):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        assert 0<=b<self.n, "0<=b<n,b={0},n={1}".format(b,self.n)
        return self.leader(a)==self.leader(b)
    def leader(self,a):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        if (self.parent_or_size[a]<0):
            return a
        self.parent_or_size[a]=self.leader(self.parent_or_size[a])
        return self.parent_or_size[a]
    def size(self,a):
        assert 0<=a<self.n, "0<=a<n,a={0},n={1}".format(a,self.n)
        return -self.parent_or_size[self.leader(a)]
    def groups(self):
        leader_buf=[0 for i in range(self.n)]
        group_size=[0 for i in range(self.n)]
        for i in range(self.n):
            leader_buf[i]=self.leader(i)
            group_size[leader_buf[i]]+=1
        result=[[] for i in range(self.n)]
        for i in range(self.n):
            result[leader_buf[i]].append(i)
        result2=[]
        for i in range(self.n):
            if len(result[i])>0:
                result2.append(result[i])
        return result2
    def count(self):
        return self.num
n, m = mi()
from math import gcd
p = list(range(n))
TA = [li() for _ in range(m)]
for x in range(m):
    t, *a = TA[x]

    a = [v - 1 for v in a]
    q = deque()
    for i in range(t):
        q.append(p[a[i]])
    q.appendleft(q.pop())

    for i in range(t):
        p[a[i]] = q.popleft()

U = dsu(n)

for i in range(n):
    U.merge(i, p[i])

G = sorted([len(v) for v in U.groups()], reverse=True)

stack = list(G)
while len(stack) >= 2:
    p = stack.pop()
    q = stack.pop()
    stack.append(p * q // gcd(p, q))

print(stack[0] % 998244353)


    
0