結果

問題 No.1604 Swap Sort:ONE
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-16 21:32:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 77,684 KB
最終ジャッジ日時 2023-09-20 13:11:43
合計ジャッジ時間 10,700 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,308 KB
testcase_01 AC 78 ms
71,276 KB
testcase_02 AC 77 ms
71,248 KB
testcase_03 AC 79 ms
71,436 KB
testcase_04 AC 74 ms
71,344 KB
testcase_05 AC 84 ms
76,016 KB
testcase_06 AC 202 ms
77,300 KB
testcase_07 AC 537 ms
77,212 KB
testcase_08 AC 544 ms
77,684 KB
testcase_09 AC 543 ms
77,204 KB
testcase_10 AC 544 ms
77,540 KB
testcase_11 AC 540 ms
77,412 KB
testcase_12 AC 542 ms
77,396 KB
testcase_13 AC 543 ms
77,608 KB
testcase_14 AC 544 ms
77,588 KB
testcase_15 AC 547 ms
77,600 KB
testcase_16 AC 545 ms
77,504 KB
testcase_17 AC 237 ms
77,092 KB
testcase_18 AC 241 ms
77,120 KB
testcase_19 AC 503 ms
77,244 KB
testcase_20 AC 222 ms
76,984 KB
testcase_21 AC 493 ms
77,156 KB
testcase_22 AC 372 ms
77,224 KB
testcase_23 AC 122 ms
76,404 KB
testcase_24 AC 95 ms
76,484 KB
testcase_25 AC 499 ms
77,240 KB
testcase_26 AC 292 ms
77,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
p = list(map(int, input().split()))
inds = [p.index(i) for i in range(1, n + 1)]
ans = 0
while True:
    if p == sorted(p): break
    for i in range(1, n):
        a, b = inds[i - 1], inds[i]
        if a > b: inds[i - 1], inds[i] = inds[i], inds[i - 1]; p[a], p[b] = p[b], p[a]; ans += 1
print(ans)
0