結果

問題 No.2289 順列ソート
ユーザー piratapirata
提出日時 2023-05-05 21:59:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,221 bytes
コンパイル時間 4,622 ms
コンパイル使用メモリ 261,080 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 16:14:38
合計ジャッジ時間 4,262 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 AC 1 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
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 just = 0;
	int swap = 0;
	int apart = 0; 
	REP(i,n){
		if(p[i] == i + 1) just++;
		else if(p[p[i] - 1] == i + 1) swap++;
		else apart++;	
	}
	// cout << just << " " << swap << " " << apart << endl;
	cout << swap / 2 + max(0,apart - 1) << endl;
}
0