結果

問題 No.2289 順列ソート
ユーザー buey_t
提出日時 2023-05-06 12:30:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,086 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 85,344 KB
最終ジャッジ日時 2024-11-23 21:15:17
合計ジャッジ時間 4,878 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from random import randrange
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
import sys
input = sys.stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353

#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!


'''



'''

N = int(input())
P = list(map(int, input().split()))

G = [0]*(N+1)
for i in range(N):
    G[P[i]] = i+1

ans = 0
for i in range(N):
    nx = P[i]
    
    if nx == i+1:
        pass
    else:
        ans += 1
        P[G[i+1]-1] = nx
        G[nx] = G[i+1]
        P[i] = i+1

print(ans)




























0