結果

問題 No.2289 順列ソート
ユーザー piratapirata
提出日時 2023-05-05 21:52:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,137 bytes
コンパイル時間 4,381 ms
コンパイル使用メモリ 262,116 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-02 15:58:40
合計ジャッジ時間 5,613 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 2 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
5,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using Graph = vector<vector<int> >;
using mint = modint998244353;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e+18;

#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define ALL(x) x.begin(),x.end()
#define VI vector<int>
#define VL vector<ll>
#define VC vector<char>
#define VVI vector<vector<int> >
#define VVL vector<vector<ll> >
#define VVC vector<vector<char> >
#define VPII vector<pair<int,int> >
#define VPLL vector<pair<ll,ll> >

template <class T>
	inline void printVec(std::vector<T> v){
	REP(i,v.size()){
	if(i) std::cout << " ";
	std::cout << v[i];
	} std::cout << std::endl;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	VI p(n);
	REP(i,n) cin >> p[i];
	int cnt = n - 1;
	int mi = 0;
	REP(i,n) if(p[i] == i + 1) cnt--;
	REP(i,n){
		if(p[p[i] - 1] == i + 1){
			mi++;
		}
	}
	mi /= 2;
	cout << max(0,cnt - mi) << endl;
}
0