結果
| 問題 |
No.1604 Swap Sort:ONE
|
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2021-07-16 22:41:24 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 328 ms / 2,000 ms |
| コード長 | 463 bytes |
| コンパイル時間 | 227 ms |
| コンパイル使用メモリ | 81,884 KB |
| 実行使用メモリ | 64,068 KB |
| 最終ジャッジ日時 | 2024-07-06 10:11:38 |
| 合計ジャッジ時間 | 4,868 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
from collections import defaultdict
n = int(input())
p = list(map(int,input().split()))
d = defaultdict(int)
for i in range(n):
d[p[i]] = i
ans = 0
for i in range(n):
if p[i] > i + 1:
plus = -1
elif p[i] < i + 1:
plus = 1
else:
continue
while p[i] != i + 1:
idx = d[p[i] + plus]
d[p[i] + plus] , d[p[i]] =d[p[i]], d[p[i] + plus]
p[i] ,p[idx] = p[idx] ,p[i]
ans += 1
print(ans)
SidewaysOwl