結果

問題 No.2428 Returning Shuffle
ユーザー porkleoi
提出日時 2023-08-18 22:27:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 271,144 KB
最終ジャッジ日時 2024-11-28 08:14:46
合計ジャッジ時間 5,431 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def lcm(a, b):
    return a * b // math.gcd(a, b)

def main():
    n, m = map(int, input().split())
    vec = list(range(n))
    
    for _ in range(m):
        input_data = list(map(int, input().split()))
        t = input_data[0]
        rol = list(map(lambda x: int(x) - 1, input_data[1:]))
        rol.reverse()
        x = vec[rol[0]]
        for j in range(t - 1):
            vec[rol[j]] = vec[rol[j + 1]]
        vec[rol[t - 1]] = x
        
    ans = 1
    che = [0] * n
    for i in range(n):
        if che[i] == 1:
            continue
        x = vec[i]
        sum_val = 0
        while True:
            sum_val += 1
            che[x] = 1
            if vec[x] == i:
                break
            x = vec[x]
        if sum_val == 1:
            continue
        ans = lcm(ans, sum_val + 1)
    
    mod = 998244353
    print(ans % mod)

if __name__ == "__main__":
    main()
0