結果

問題 No.2428 Returning Shuffle
ユーザー ThetaTheta
提出日時 2024-03-06 19:17:30
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 997 bytes
コンパイル時間 491 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 376,340 KB
最終ジャッジ日時 2024-03-06 19:17:45
合計ジャッジ時間 13,620 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 37 ms
53,588 KB
testcase_04 AC 36 ms
53,588 KB
testcase_05 AC 37 ms
53,588 KB
testcase_06 AC 37 ms
53,588 KB
testcase_07 AC 37 ms
53,588 KB
testcase_08 AC 37 ms
53,588 KB
testcase_09 AC 37 ms
53,588 KB
testcase_10 AC 37 ms
53,588 KB
testcase_11 AC 38 ms
53,588 KB
testcase_12 AC 37 ms
53,588 KB
testcase_13 AC 36 ms
53,588 KB
testcase_14 AC 36 ms
53,588 KB
testcase_15 AC 36 ms
53,588 KB
testcase_16 AC 36 ms
53,588 KB
testcase_17 AC 37 ms
53,588 KB
testcase_18 AC 36 ms
53,588 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 36 ms
53,588 KB
testcase_22 AC 36 ms
53,588 KB
testcase_23 AC 36 ms
53,588 KB
testcase_24 AC 1,144 ms
376,340 KB
testcase_25 AC 1,119 ms
376,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import chain
from math import lcm


def main():
    N, M = map(int, input().split())
    replaces = []
    for _ in range(M):
        _, *S = map(lambda n: int(n) - 1, input().split())
        replaces.append(list(S))

    array = list(range(N))

    for replace_ in replaces:
        prev = -1
        for pos, new in zip(replace_, chain(replace_[-1:], replace_[:-1])):

            if prev == -1:
                array[pos], prev = array[new], array[pos]
            else:
                array[pos], prev = prev, array[pos]
    corresponds = dict(enumerate(array))

    rest = set(range(N))
    interval = [1] * N
    for idx in range(N):
        if idx not in rest:
            continue
        current = idx
        current = corresponds[current]
        while current != idx:
            interval[idx] += 1
            rest.discard(current)
            current = corresponds[current]
        rest.discard(idx)
    print(lcm(*interval))


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