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 <bits/stdc++.h>
using namespace std;
vector<int> s;
int n;
bool sorted() {
for (int i = 0; i < n; i++)
{
if (s[i] != i)
{
return false;
}
}
return true;
}
int findSwapPairs(int N,int S[],int M, int X[],int Y[], int P[],int Q[]) {
for (int i = 0; i < M; i++)
{
P[i] = 0;
Q[i] = 0;
}
n = N;
for (int i = 0; i < N; i++)
{
s.push_back(S[i]);
}
for (int i = 0; i < N; i++)
{
if (sorted())
{
return i;
}
swap(s[X[i]], s[Y[i]]);
swap(S[X[i]], S[Y[i]]);
for (int j = 0; j < N; j++)
{
if (S[j] == i)
{
P[i] = j;
Q[i] = i;
swap(s[j], s[i]);
swap(S[j], S[i]);
break;
}
if (j == N-1)
{
assert(false);
}
}
}
assert(sorted());
return N;
}
# | 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... |