結果

問題 No.1604 Swap Sort:ONE
ユーザー kozykozy
提出日時 2021-07-16 22:11:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 425 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 10,876 KB
実行使用メモリ 13,120 KB
最終ジャッジ日時 2023-09-20 14:17:22
合計ジャッジ時間 3,834 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,188 KB
testcase_01 AC 15 ms
7,792 KB
testcase_02 AC 18 ms
7,684 KB
testcase_03 AC 18 ms
7,684 KB
testcase_04 AC 17 ms
7,904 KB
testcase_05 AC 18 ms
8,544 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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