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;
int findSwapPairs(
int N, int S[], int M, int X[], int Y[], int P[], int Q[]
) {
if (N == 1) return 0;
for (int t=0; t<N; t++) {
for (int i=1; i<N; i++) {
if (S[i] < S[i-1]) break;
if (i == N-1) return t;
}
swap(S[X[t]], S[Y[t]]);
int permut[N];
for (int i=0; i<N; i++) permut[i] = i;
for (int i=t+1; i<M; i++) {
swap(permut[X[i]], permut[Y[i]]);
}
int a=0, b=0;
for (int i=0; i<N; i++) {
if (S[i] == t) a = i;
}
b = permut[t];
swap(S[a], S[b]);
P[t] = a; Q[t] = b;
}
// cout << "ans = ";
// for (int i=0; i<N; i++) cout << S[i] << ' ';
// cout << endl;
for (int t=N; t<M; t++) {
P[t] = Q[t] = 0;
}
return M;
}
# | 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... |