結果

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

ソースコード

diff #

n, k = map(int, input().split())
a = list(map(int, input().split()))

state_map = {}
history = []

current = a.copy()
step = 0
state_map[tuple(current)] = step
history.append(current.copy())

found_cycle = False

while step < k:
    if step == k:
        break
    x = current[0]
    m = x + 1
    if m > n:
        m = n
    rotated = current[1:m] + [current[0]]
    new_array = rotated + current[m:]
    current = new_array
    step += 1
    current_tuple = tuple(current)
    if current_tuple in state_map:
        # Cycle detected
        prev_step = state_map[current_tuple]
        cycle_length = step - prev_step
        remaining = k - step
        remaining %= cycle_length
        for _ in range(remaining):
            x = current[0]
            m = x + 1
            if m > n:
                m = n
            rotated = current[1:m] + [current[0]]
            new_array = rotated + current[m:]
            current = new_array
        found_cycle = True
        break
    else:
        state_map[current_tuple] = step
        history.append(current.copy())

if not found_cycle:
    current = history[-1]

print(' '.join(map(str, current)))
0