結果

問題 No.2428 Returning Shuffle
ユーザー mono_0812mono_0812
提出日時 2023-08-18 22:10:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 821 ms / 2,000 ms
コード長 3,526 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 264,932 KB
最終ジャッジ日時 2024-05-06 04:17:23
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 296 ms
117,004 KB
testcase_01 AC 821 ms
214,656 KB
testcase_02 AC 814 ms
214,656 KB
testcase_03 AC 145 ms
93,056 KB
testcase_04 AC 141 ms
93,108 KB
testcase_05 AC 151 ms
93,184 KB
testcase_06 AC 141 ms
93,056 KB
testcase_07 AC 139 ms
93,056 KB
testcase_08 AC 142 ms
92,928 KB
testcase_09 AC 147 ms
93,004 KB
testcase_10 AC 143 ms
93,056 KB
testcase_11 AC 141 ms
93,092 KB
testcase_12 AC 145 ms
92,956 KB
testcase_13 AC 142 ms
93,056 KB
testcase_14 AC 144 ms
92,928 KB
testcase_15 AC 149 ms
93,032 KB
testcase_16 AC 139 ms
93,056 KB
testcase_17 AC 140 ms
93,056 KB
testcase_18 AC 139 ms
92,980 KB
testcase_19 AC 343 ms
116,608 KB
testcase_20 AC 350 ms
116,480 KB
testcase_21 AC 139 ms
93,056 KB
testcase_22 AC 137 ms
92,988 KB
testcase_23 AC 140 ms
92,968 KB
testcase_24 AC 468 ms
264,820 KB
testcase_25 AC 468 ms
264,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

############################################################################################
import bisect,collections,copy,heapq,itertools,math,string,sys,queue,time,random
from decimal import Decimal
def I(): return input()
def IS(): return input().split()
def II(): return int(input())
def IIS(): return list(map(int,input().split()))
def LIIS(): return list(map(int,input().split()))

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

import math

def prime_numbers(n):
    prime = [True for i in range(n+1)]
    prime[0] = False
    prime[1] = False

    sqrt_n = math.ceil(math.sqrt(n))
    for i in range(2, sqrt_n):
        if prime[i]:
            for j in range(2*i, n+1, i):
                prime[j] = False
    numbers=[]
    for i in range(2,n+1):
        if prime[i]:
            numbers.append(i)

    return numbers

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
 
    if temp!=1:
        arr.append([temp, 1])
 
    if arr==[] and n>1:
        arr.append([n, 1])
 
    return arr
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        group_members = defaultdict(list)
        for member in range(self.n):
            group_members[self.find(member)].append(member)
        return group_members

    def __str__(self):
        return '\n'.join(f'{r}: {m}' for r, m in self.all_group_members().items())
 
INF=10**18
MOD=998244353
MOD2=10**9+7
sys.setrecursionlimit(500005)
def bit_count(x):
    return bin(x).count("1")
def yesno(f):
    if f:print("Yes")
    else:print("No")
dxy=((1,0),(0,-1),(-1,0),(0,1))
##################################################################
n,m=IIS()
s=[]
t=[]
for i in range(m):
    li=LIIS()
    t.append(li[0])
    s.append(li[1:])

li=list(range(1,n+1))
for i in range(m):
    v=li[s[i][0]-1]
    for j in range(t[i]):
        v2=v
        v=li[s[i][(j+1)%t[i]]-1]
        li[s[i][(j+1)%t[i]]-1]=v2

used=[0]*n
ans=1
for i in range(n):
    if used[i]:continue
    if i==li[i]-1:continue
    cnt=0
    v=i
    while True:
        used[v]=1
        v=li[v]-1
        cnt+=1
        if v==i:
            break
        
    ans=math.lcm(cnt,ans)
print(ans%MOD)
0