結果

問題 No.2289 順列ソート
ユーザー AkariAkari
提出日時 2023-05-05 21:25:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 323 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 10,716 KB
実行使用メモリ 29,920 KB
最終ジャッジ日時 2023-08-15 02:46:59
合計ジャッジ時間 7,428 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
29,848 KB
testcase_01 AC 133 ms
29,676 KB
testcase_02 AC 131 ms
29,616 KB
testcase_03 AC 131 ms
29,832 KB
testcase_04 AC 134 ms
29,820 KB
testcase_05 AC 130 ms
29,832 KB
testcase_06 AC 136 ms
29,696 KB
testcase_07 AC 134 ms
29,676 KB
testcase_08 AC 135 ms
29,836 KB
testcase_09 AC 131 ms
29,752 KB
testcase_10 AC 131 ms
29,664 KB
testcase_11 AC 130 ms
29,812 KB
testcase_12 AC 131 ms
29,848 KB
testcase_13 AC 133 ms
29,752 KB
testcase_14 AC 130 ms
29,752 KB
testcase_15 AC 131 ms
29,804 KB
testcase_16 AC 130 ms
29,816 KB
testcase_17 AC 131 ms
29,848 KB
testcase_18 AC 129 ms
29,848 KB
testcase_19 AC 136 ms
29,920 KB
testcase_20 AC 132 ms
29,804 KB
testcase_21 AC 133 ms
29,824 KB
testcase_22 AC 132 ms
29,832 KB
testcase_23 AC 132 ms
29,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import numpy as np



def main():
    n = int(input())
    P = np.fromstring(input(), np.int64, sep=' ') - 1
    ans = 0
    for i in range(n):
        if P[i] == i: continue
        j, = np.nonzero(P == i)
        P[i], P[j] = P[j], P[i]
        ans += 1
    print(ans)




if __name__ == '__main__':
    main()
0