結果

問題 No.2428 Returning Shuffle
ユーザー porkleoiporkleoi
提出日時 2023-08-18 22:27:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 908 bytes
コンパイル時間 1,111 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 271,268 KB
最終ジャッジ日時 2024-05-06 04:44:22
合計ジャッジ時間 5,655 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 686 ms
92,788 KB
testcase_02 AC 685 ms
93,172 KB
testcase_03 AC 42 ms
52,096 KB
testcase_04 WA -
testcase_05 AC 42 ms
52,352 KB
testcase_06 WA -
testcase_07 AC 42 ms
52,096 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 42 ms
52,096 KB
testcase_11 AC 41 ms
52,224 KB
testcase_12 AC 42 ms
52,224 KB
testcase_13 WA -
testcase_14 AC 42 ms
51,840 KB
testcase_15 WA -
testcase_16 AC 41 ms
51,968 KB
testcase_17 AC 41 ms
52,224 KB
testcase_18 WA -
testcase_19 AC 286 ms
92,416 KB
testcase_20 AC 285 ms
92,800 KB
testcase_21 AC 41 ms
52,096 KB
testcase_22 AC 42 ms
52,352 KB
testcase_23 AC 41 ms
52,096 KB
testcase_24 AC 451 ms
271,240 KB
testcase_25 AC 443 ms
271,268 KB
権限があれば一括ダウンロードができます

ソースコード

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