제출 #1018781

#제출 시각아이디문제언어결과실행 시간메모리
1018781parsadox2정렬하기 (IOI15_sorting)C++17
36 / 100
8 ms592 KiB
#include "sorting.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 2e3 + 10;
int n , ar[N] , pos[N] , m;

int findSwapPairs(int nn, int S[], int mm, int X[], int Y[], int P[], int Q[]) {
	n = nn;
	m = mm;
	for(int i = 0 ; i < n ; i++)
		ar[i] = S[i];
	int R = 0;
	for(int i = 0 ; i < m ; i++)
	{
		R = i + 1;
		P[i] = Q[i] = 0;
		swap(ar[X[i]] , ar[Y[i]]);
		for(int j = 0 ; j < n ; j++)
			pos[ar[j]] = j;
		bool flg = false;
		for(int j = 2 ; j < n ; j++)  if(pos[j] != j)
		{
			swap(ar[j] , ar[pos[j]]);
			P[i] = j;
			Q[i] = pos[j];
			flg = true;
			break;
		}
		if(flg)
			continue;
		if(pos[0] != 0)
			Q[i] = 1;
		break;
	}
	return R;
}
#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...