This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "sorting.h"
#include "bits/stdc++.h"
using namespace std;
const int mxN = 2e5 + 7;
int n, m, arr[mxN];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N, m = M;
for (int i = 0; i < n; ++i) {
arr[i] = S[i];
}
int R = 0, ind = 0;
bool ok = false;
for (int iter = 1; iter <= m && !ok; ++iter) {
swap(arr[X[ind]], arr[Y[ind]]);
ok = true;
for (int i = 0; i < n && ok; ++i) {
if (ind + 1 < m && (i == X[ind + 1] || i == Y[ind + 1]))
continue;
for (int j = 0; j < n && ok; ++j) {
if (arr[j] == i && i != j) {
swap(arr[j], arr[i]);
P[ind] = j, Q[ind] = i;
++R;
++ind;
ok = false;
}
}
}
for (int i = 0; i < n; ++i) {
if (arr[i] != i) {
ok = false;
}
}
}
return R;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |