제출 #1229115

#제출 시각아이디문제언어결과실행 시간메모리
1229115PlayVoltz정렬하기 (IOI15_sorting)C++20
20 / 100
1 ms584 KiB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;

#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n;
vector<int> ss, x, y;
vector<pii> ans;

bool check(int m){
	ans.clear();
	vector<int> f(n), id(n), s=ss;
	for (int i=0; i<n; ++i)f[i]=i, id[s[i]]=i;
	for (int i=0; i<m; ++i)swap(f[x[i]], f[y[i]]);
	for (int i=0; i<n; ++i)if (s[f[i]]!=i){
		ans.pb(mp(f[i], id[i]));
		swap(id[i], id[s[f[i]]]);
		swap(s[ans.back().fi], s[ans.back().se]);
	}
	return ans.size()<=m;
}

int findSwapPairs(int N, int S[], int m, int X[], int Y[], int p[], int q[]){
	n=N;
	ss.clear();
	x.clear();
	y.clear();
	ss.resize(n);
	x.resize(m);
	y.resize(m);
	for (int i=0; i<n; ++i)ss[i]=S[i];
	for (int i=0; i<m; ++i)x[i]=X[i], y[i]=Y[i];
	int low=-1, high=m+1;
	while (low+1<high){
		int mid=(low+high)/2;
		if (check(mid))high=mid;
		else low=mid;
	}
	check(high);
	for (int i=0; i<high; ++i)p[i]=ans[i].fi, q[i]=ans[i].se;
	return high;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...