結果

問題 No.1379 Postponed
ユーザー lam6er
提出日時 2025-04-15 22:54:34
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 940 bytes
コンパイル時間 1,666 ms
コンパイル使用メモリ 81,452 KB
実行使用メモリ 848,276 KB
最終ジャッジ日時 2025-04-15 22:56:18
合計ジャッジ時間 11,137 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40 MLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if k == 0:
    print(' '.join(map(str, a)))
    exit()

history = {}
current = tuple(a)
history[current] = 0
steps = 0
found_cycle = False

while steps < k:
    x = a[0]
    m = x + 1
    if m > len(a):
        rotated = a[1:] + [a[0]]
    else:
        rotated = a[1:m] + [a[0]] + a[m:]
    a = rotated
    steps += 1
    current = tuple(a)
    if current in history:
        # Cycle detected
        prev_step = history[current]
        cycle_length = steps - prev_step
        remaining = (k - steps) % cycle_length
        for _ in range(remaining):
            x = a[0]
            m = x + 1
            if m > len(a):
                rotated = a[1:] + [a[0]]
            else:
                rotated = a[1:m] + [a[0]] + a[m:]
            a = rotated
        found_cycle = True
        break
    else:
        history[current] = steps

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