結果

問題 No.1604 Swap Sort:ONE
ユーザー 👑 KazunKazun
提出日時 2021-07-16 21:29:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 117 ms / 2,000 ms
コード長 333 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 76,608 KB
最終ジャッジ日時 2023-09-20 13:03:44
合計ジャッジ時間 3,815 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,284 KB
testcase_01 AC 72 ms
71,136 KB
testcase_02 AC 72 ms
71,248 KB
testcase_03 AC 72 ms
71,316 KB
testcase_04 AC 71 ms
71,484 KB
testcase_05 AC 78 ms
76,344 KB
testcase_06 AC 117 ms
76,404 KB
testcase_07 AC 98 ms
76,544 KB
testcase_08 AC 99 ms
76,572 KB
testcase_09 AC 99 ms
76,304 KB
testcase_10 AC 99 ms
76,400 KB
testcase_11 AC 98 ms
76,200 KB
testcase_12 AC 99 ms
76,608 KB
testcase_13 AC 97 ms
76,240 KB
testcase_14 AC 98 ms
76,208 KB
testcase_15 AC 97 ms
76,436 KB
testcase_16 AC 99 ms
76,208 KB
testcase_17 AC 86 ms
76,308 KB
testcase_18 AC 86 ms
76,360 KB
testcase_19 AC 96 ms
76,388 KB
testcase_20 AC 86 ms
76,284 KB
testcase_21 AC 96 ms
76,400 KB
testcase_22 AC 93 ms
76,328 KB
testcase_23 AC 78 ms
75,768 KB
testcase_24 AC 78 ms
75,752 KB
testcase_25 AC 97 ms
76,108 KB
testcase_26 AC 88 ms
76,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#=================================================
N=int(input())
P=[0]+list(map(int,input().split()))
P_inv=[0]*(N+1)

for i in range(N+1):
    P_inv[P[i]]=i

X=0
for i in range(N+1):
    while P[i]!=i:
        X+=1
        j=P_inv[P[i]-1]
        a=P[i]; b=P[j]
        P[i],P[j]=P[j],P[i]
        P_inv[a], P_inv[b]=j,i

print(X)
0