제출 #1226189

#제출 시각아이디문제언어결과실행 시간메모리
1226189faruk정렬하기 (IOI15_sorting)C++20
16 / 100
9 ms328 KiB
#include "sorting.h"
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()

using namespace std;

int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
	
	for (int i = 0; i < M; i++) {
		// create temp array and do all the swaps
		swap(S[X[i]], S[Y[i]]);
		vector<int> tmp(S, S + N);
		for (int j = i + 1; j < M; j++)	
			swap(tmp[X[j]], tmp[Y[j]]);
		
		int get_to_right_place = -1;
		for (int j = 0; j < N; j++) 
			if (tmp[j] != j)
				get_to_right_place = j;

		if (get_to_right_place == -1)
		{
			for (int j = i; j < M; j++)
				P[j] = Q[j] = 0;
			break;
		}
		int in_my_place = tmp[get_to_right_place];

		int id1 = find(S, S + N, get_to_right_place) - S, id2 = find(S, S + N, in_my_place) - S;
		swap(S[id1], S[id2]);
		P[i] = id1, Q[i] = id2;
	}

	return M;
}


#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...