結果

問題 No.1379 Postponed
ユーザー gew1fw
提出日時 2025-06-12 18:08:15
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,204 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 904,908 KB
最終ジャッジ日時 2025-06-12 18:10:07
合計ジャッジ時間 9,624 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 MLE * 1
other AC * 40 MLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    N, K = map(int, sys.stdin.readline().split())
    A = list(map(int, sys.stdin.readline().split()))
    if K == 0:
        print(' '.join(map(str, A)))
        return
    
    history = {}
    current = A.copy()
    history[tuple(current)] = 0
    steps = 0
    found_cycle = False
    
    while steps < K:
        s_prev = current[0]
        m = s_prev + 1
        next_arr = current[1:m] + [current[0]] + current[m:]
        steps += 1
        key = tuple(next_arr)
        if key in history:
            prev_step = history[key]
            cycle_len = steps - prev_step
            remaining = K - steps
            remaining %= cycle_len
            K = prev_step + remaining
            current = next_arr.copy()
            for _ in range(K - prev_step):
                s_prev = current[0]
                m = s_prev + 1
                next_arr = current[1:m] + [current[0]] + current[m:]
                current = next_arr.copy()
            print(' '.join(map(str, current)))
            return
        else:
            history[key] = steps
            current = next_arr.copy()
    
    print(' '.join(map(str, current)))

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