結果

問題 No.1604 Swap Sort:ONE
ユーザー tcltktcltk
提出日時 2021-10-19 06:44:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 671 bytes
コンパイル時間 471 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 88,772 KB
最終ジャッジ日時 2023-10-20 10:11:38
合計ジャッジ時間 6,991 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
86,072 KB
testcase_01 AC 126 ms
86,068 KB
testcase_02 AC 129 ms
86,076 KB
testcase_03 AC 127 ms
86,072 KB
testcase_04 AC 125 ms
86,072 KB
testcase_05 AC 129 ms
86,928 KB
testcase_06 AC 159 ms
88,764 KB
testcase_07 AC 150 ms
88,764 KB
testcase_08 AC 151 ms
88,764 KB
testcase_09 AC 149 ms
88,764 KB
testcase_10 AC 148 ms
88,764 KB
testcase_11 AC 150 ms
88,764 KB
testcase_12 AC 148 ms
88,764 KB
testcase_13 AC 152 ms
88,764 KB
testcase_14 AC 151 ms
88,764 KB
testcase_15 AC 155 ms
88,764 KB
testcase_16 AC 150 ms
88,752 KB
testcase_17 AC 143 ms
88,692 KB
testcase_18 AC 142 ms
88,696 KB
testcase_19 AC 153 ms
88,764 KB
testcase_20 AC 141 ms
88,696 KB
testcase_21 AC 150 ms
88,744 KB
testcase_22 AC 143 ms
88,768 KB
testcase_23 AC 141 ms
88,456 KB
testcase_24 AC 136 ms
88,508 KB
testcase_25 AC 149 ms
88,772 KB
testcase_26 AC 144 ms
88,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)

# _INPUT = """3
# 3 2 1

# """
# sys.stdin = io.StringIO(_INPUT)

INF = 10**10

N = int(input())
A = list(map(lambda x: int(x)-1, input().split()))

Pos = [-1] * N
for i in range(N):
    Pos[A[i]] = i

n = 0
for i in range(N):
    while A[i] > i:
        for k in reversed(range(i, A[i])):
            A[Pos[k]] = k+1
            Pos[k+1] = Pos[k]
            n += 1
        A[i] = i
        Pos[i] = i

print(n)            
0