結果

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

ソースコード

diff #

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

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

memo = {}
current = tuple(a)
memo[current] = 0
steps = 0
history = [a.copy()]
cycle_found = False

while steps < k:
    x = current[0]
    m = x + 1
    new_list = list(current)[1:m] + [current[0]] + list(current)[m:]
    steps += 1
    new_tuple = tuple(new_list)
    if new_tuple in memo:
        prev_step = memo[new_tuple]
        cycle_length = steps - prev_step
        remaining = (k - steps) % cycle_length
        for _ in range(remaining):
            x = new_list[0]
            m = x + 1
            new_list = new_list[1:m] + [new_list[0]] + new_list[m:]
        print(' '.join(map(str, new_list)))
        cycle_found = True
        break
    else:
        memo[new_tuple] = steps
        current = new_tuple
        history.append(new_list)

if not cycle_found:
    print(' '.join(map(str, current)))
0