結果

問題 No.1604 Swap Sort:ONE
ユーザー kozykozy
提出日時 2021-07-16 22:11:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 425 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,120 KB
実行使用メモリ 76,740 KB
最終ジャッジ日時 2023-09-20 14:17:58
合計ジャッジ時間 4,234 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,596 KB
testcase_01 AC 74 ms
71,284 KB
testcase_02 AC 73 ms
71,376 KB
testcase_03 AC 75 ms
71,476 KB
testcase_04 AC 76 ms
71,568 KB
testcase_05 AC 82 ms
76,396 KB
testcase_06 AC 130 ms
76,500 KB
testcase_07 AC 107 ms
76,684 KB
testcase_08 AC 110 ms
76,540 KB
testcase_09 AC 109 ms
76,704 KB
testcase_10 AC 109 ms
76,728 KB
testcase_11 AC 108 ms
76,560 KB
testcase_12 AC 110 ms
76,660 KB
testcase_13 AC 110 ms
76,732 KB
testcase_14 AC 109 ms
76,668 KB
testcase_15 AC 109 ms
76,620 KB
testcase_16 AC 110 ms
76,740 KB
testcase_17 AC 95 ms
76,632 KB
testcase_18 AC 95 ms
76,720 KB
testcase_19 AC 107 ms
76,672 KB
testcase_20 AC 93 ms
76,532 KB
testcase_21 AC 105 ms
76,668 KB
testcase_22 AC 101 ms
76,620 KB
testcase_23 AC 86 ms
76,228 KB
testcase_24 AC 84 ms
76,504 KB
testcase_25 AC 108 ms
76,652 KB
testcase_26 AC 98 ms
76,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
ans=0
L=list(map(int,input().split()))
L=[i-1 for i in L]
ind=[-1]*N
ans=0
for i in range(N):
  ind[L[i]]=i
for i in range(N):
  if L[i]==i:
    continue
  else:
    for j in range(L[i]-1,i-1,-1):
      #L[i]とL[i]-1を入れ替える
      #ind[j]はL[i]になる
      a,b=L[i],j
      L[i],L[ind[j]],ind[j],ind[L[i]]=L[ind[j]],L[i],ind[L[i]],ind[j]
      ind[a],ind[b]=ind[b],ind[a]
      ans+=1
print(ans)
0