結果

問題 No.3489 あみだくじ作り
コンテスト
ユーザー LyricalMaestro
提出日時 2026-04-04 18:43:14
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 798 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 538 ms
コンパイル使用メモリ 85,376 KB
実行使用メモリ 63,616 KB
最終ジャッジ日時 2026-04-04 18:43:25
合計ジャッジ時間 1,935 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/3489



def main():
    N = int(input())
    P = list(map(int, input().split()))

    Q = [-1] * N
    for i in range(N):
        Q[P[i] - 1] = i + 1
    P = Q

    # ターゲット
    answer = []
    current = [i + 1 for i in range(N)]
    for i in range(N):
        p = P[i]

        if p == current[i]:
            continue


        for j in range(i + 1, N):
            if p == current[j]:
                for k in reversed(range(i, j)):
                    answer.append(k + 1)
                    tmp = current[k]
                    current[k] = current[k + 1]
                    current[k + 1] = tmp
    
    print("Yes")
    print(len(answer))
    for a in answer:
        print(a)



            
        





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