結果

問題 No.1604 Swap Sort:ONE
ユーザー wolgnikwolgnik
提出日時 2021-07-16 22:27:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 378 ms / 2,000 ms
コード長 455 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 76,944 KB
最終ジャッジ日時 2023-09-20 14:42:08
合計ジャッジ時間 8,997 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
76,420 KB
testcase_01 AC 82 ms
76,444 KB
testcase_02 AC 82 ms
76,404 KB
testcase_03 AC 80 ms
76,164 KB
testcase_04 AC 81 ms
76,164 KB
testcase_05 AC 237 ms
76,768 KB
testcase_06 AC 358 ms
76,784 KB
testcase_07 AC 377 ms
76,912 KB
testcase_08 AC 377 ms
76,696 KB
testcase_09 AC 377 ms
76,596 KB
testcase_10 AC 377 ms
76,632 KB
testcase_11 AC 376 ms
76,772 KB
testcase_12 AC 376 ms
76,652 KB
testcase_13 AC 378 ms
76,764 KB
testcase_14 AC 378 ms
76,684 KB
testcase_15 AC 378 ms
76,824 KB
testcase_16 AC 377 ms
76,736 KB
testcase_17 AC 266 ms
76,852 KB
testcase_18 AC 266 ms
76,896 KB
testcase_19 AC 363 ms
76,768 KB
testcase_20 AC 256 ms
76,756 KB
testcase_21 AC 364 ms
76,780 KB
testcase_22 AC 322 ms
76,944 KB
testcase_23 AC 175 ms
76,396 KB
testcase_24 AC 140 ms
76,640 KB
testcase_25 AC 364 ms
76,856 KB
testcase_26 AC 294 ms
76,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
table = [0] * N
for i in range(N): table[a[i] - 1] = i

res = 0
for _ in range(10000):
  for i in range(N):
    if i - 1 in range(N) and table[i - 1] > table[i]:
      table[i - 1], table[i] = table[i], table[i - 1]
      res += 1
    if i + 1 in range(N) and table[i + 1] < table[i]:
      table[i + 1], table[i] = table[i], table[i + 1]
      res += 1
print(res)
0