結果

問題 No.1379 Postponed
ユーザー lam6er
提出日時 2025-03-31 17:31:40
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,073 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,588 KB
実行使用メモリ 856,628 KB
最終ジャッジ日時 2025-03-31 17:32:35
合計ジャッジ時間 10,610 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 40 MLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    idx = 0
    n = int(input[idx])
    idx += 1
    k = int(input[idx])
    idx += 1
    a = list(map(int, input[idx:idx + n]))
    idx += n

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

    states = {}
    history = [a.copy()]
    states[tuple(a)] = 0
    current = a.copy()
    step = 0

    while step < k:
        s = current[0]
        next_arr = current[1:s+1] + [current[0]] + current[s+1:]
        step += 1
        current = next_arr
        current_tuple = tuple(current)

        if current_tuple in states:
            prev_step = states[current_tuple]
            cycle_length = step - prev_step
            remaining_steps = k - prev_step
            effective_step = prev_step + (remaining_steps % cycle_length)
            print(' '.join(map(str, history[effective_step])))
            return
        else:
            states[current_tuple] = step
            history.append(current.copy())

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

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