Submission #1337182

#TimeUsernameProblemLanguageResultExecution timeMemory
1337182tsetsenbilegSorting (IOI15_sorting)C++20
36 / 100
9 ms13124 KiB
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
using ll = long long;
using ld = long double;
using pr = pair<int, int>;
const int MOD = 1e9+7, MAXA = 1e6;

int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
	vector<int> cur(n);
	for (int i = 0; i < n; i++) cur[i] = i;
	vector<vector<int>> srt(n), poss(n, vector<int>(n));
    for (int i = n-1; i >= 0; i--) {
		swap(cur[x[i]], cur[y[i]]);
		// srt[i] = cur;
		for (int j = 0; j < n; j++) {
			poss[i][cur[j]] = j;
		}
	}
	vector<int> pos(n), curr(n);
	for (int i = 0; i < n; i++) {
		pos[s[i]] = i; // where a color resides
		curr[i] = s[i]; // holds the color of a point
	}
	for (int i = 0; i <= n; i++) {
		if (is_sorted(pos.begin(), pos.end())) {
			return i;
		}
		if (i >= n) break;
		swap(pos[curr[x[i]]], pos[curr[y[i]]]);
		swap(curr[x[i]], curr[y[i]]);
		p[i] = pos[i];
		q[i] = poss[i][i];
		swap(pos[i], pos[curr[poss[i][i]]]);
		swap(curr[p[i]], curr[q[i]]);
	}
	return n;
}
#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...