結果

問題 No.2428 Returning Shuffle
ユーザー ThetaTheta
提出日時 2024-03-06 19:16:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,024 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 395,632 KB
最終ジャッジ日時 2024-03-06 19:16:55
合計ジャッジ時間 18,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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])):
            print(pos, new)
            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