結果

問題 No.1379 Postponed
ユーザー lam6er
提出日時 2025-04-15 22:51:37
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,512 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 81,884 KB
実行使用メモリ 856,892 KB
最終ジャッジ日時 2025-04-15 22:54:18
合計ジャッジ時間 9,934 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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()

seen = {}
current = a.copy()
steps = 0
seen[tuple(current)] = steps
history = [current.copy()]

cycle_found = False

while steps < k:
    x = current[0]
    m = x + 1
    next_arr = []
    # Process the first m elements
    if m > len(current):
        m = len(current)
    for i in range(1, m):
        next_arr.append(current[i])
    next_arr.append(current[0])
    # Add the remaining elements
    next_arr.extend(current[m:])
    current = next_arr
    steps += 1
    # Check if current state has been seen before
    current_tuple = tuple(current)
    if current_tuple in seen:
        prev_step = seen[current_tuple]
        cycle_length = steps - prev_step
        remaining = k - steps
        if remaining > 0:
            remaining %= cycle_length
            # Simulate remaining steps
            for _ in range(remaining):
                x = current[0]
                m = x + 1
                next_arr = []
                for i in range(1, m):
                    next_arr.append(current[i])
                next_arr.append(current[0])
                next_arr.extend(current[m:])
                current = next_arr
        cycle_found = True
        break
    else:
        seen[current_tuple] = steps
        history.append(current.copy())

if not cycle_found:
    # Simulate remaining steps if no cycle found (steps == k)
    pass

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