Submission #1245557

#TimeUsernameProblemLanguageResultExecution timeMemory
1245557santi3223Sorting (IOI15_sorting)C++20
0 / 100
1 ms328 KiB
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
#define ll long long
#define vb vector<bool>
#define pb push_back
#define ff(aa, bb, cc) for(int aa = bb; aa < cc; aa++)
#define vl vector<ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define ed "\n"
#define all(aaa) aaa.begin(), aaa.end()
#define rall(aaa) aaa.rbegin(), aaa.rend()
ll MOD = 1e9+7;


int findSwapPairs(int n, int S[], int M, int X[], int Y[], int P[], int Q[]){
	vector<int> pos(n);
	ff(i, 0, n){
		//cout << S[i] << " " << i << ed;
		pos[S[i]] = i;
	}
	int c = 0;
	vector<int> p, q;
	/*ff(id, 0, n){
		cout << pos[id] << " ";
	}
	cout << ed << ed;
	
	ff(id, 0, n){
		cout << S[id] << " ";
	}
	cout << ed << ed;*/
	ff(i, 0, n){
		if(pos[i] != i){
			p.pb(0);
			q.pb(0);
			//cout << pos[i] << " " << i << ed;
			//cout << S[pos[i]] << " " << S[i] << ed;
			p.pb(S[pos[i]]);
			q.pb(pos[i]);
			
			swap(S[pos[i]], S[i]);
			swap(pos[S[pos[i]]], pos[S[i]]);
			
		}
		/*ff(id, 0, n){
			cout << S[id] << " ";
		}
		cout << ed << ed << ed;*/
	}
	ff(i, 0, p.size()){
		P[i] = p[i];
		Q[i] = q[i];
	}
	return c;
	
}
/*
int main()
{
	int N, M;
	cin >> N;
	int S[N];
	ff(i, 0, N){
		cin >> S[i];
	}
	cin >> M;
	int X[M], Y[M];
	ff(i, 0, M){
		cin >> X[i] >> Y[i];
	}
	int P[M], Q[M];
	int x = findSwapPairs(N, S, M, X, Y, P, Q);
	cout << x << ed;
	ff(i, 0, M){
		cout << P[i] << " " << Q[i] << ed;
	}
	return 0;
}
*/
#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...