結果

問題 No.2289 順列ソート
ユーザー magurofly
提出日時 2023-05-05 21:42:22
言語 Ruby
(3.4.1)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 261 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-23 06:38:28
合計ジャッジ時間 3,840 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
P = gets.split.map(&:to_i).map(&:pred)
indices = [0] * N
N.times do |i|
	indices[P[i]] = i
end

ans = 0
N.times do |x|
	if indices[x] > x
		ans += 1
		y = P[x]
		indices[x], indices[y] = indices[y], indices[x]
		P[indices[y]] = y
	end
end
puts ans
0