#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
int n,m;
pair<int,int> his[200005];
int init[200005],ord[200005],unde[200005];
void do_swaps(int suff)
{
for(int i=suff;i<m;i++)
swap(ord[his[i].first], ord[his[i].second]);
}
bool is_sorted()
{
for(int i=1;i<n;i++)
if(ord[i]<=ord[i-1])
return 0;
return 1;
}
int findSwapPairs(int N, int copS[], int M, int X[], int Y[], int P[], int Q[])
{
n = N;
m = M;
for(int i=0;i<N;i++)
{
init[i] = copS[i];
}
for(int i=0;i<M;i++)
{
his[i] = {X[i], Y[i]};
}
for(int pas=0;pas<M;pas++)
{
for(int i=0;i<N;i++)
ord[i] = init[i];
for(int i=0;i<=pas;i++)
swap(ord[X[i]],ord[Y[i]]);
for(int i=0;i<N;i++)
unde[ord[i]] = i;
//do_swaps(pas+1);
pair<int,int> aux = {-1,-1};
for(int i=0;i<N;i++)
{
for(int j=i+1;j<N;j++)
{
if(ord[i] > ord[j])
{
aux = {i,j};
break;
}
}
}
if(aux.first!=-1)
{
P[pas] = unde[aux.first];
Q[pas] = unde[aux.second];
}
if(is_sorted())
return pas;
}
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... |