#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
bool check(int n, int s[], int r, int x[], int y[], int p[], int q[]) {
for (int i=0; i<r; i++) {
swap(s[x[i]],s[y[i]]);
swap(s[p[i]],s[q[i]]);
}
bool ok=1;
for (int i=0; i<n; i++) {
ok&=(s[i]==i);
}
return ok;
}
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
int ss[n];
for (int i=0; i<n; i++) {
ss[i]=s[i];
}
for (int i=0; i<n-1; i++) {
p[i]=i;
q[i]=find(s,s+n,i)-s;
swap(s[p[i]],s[q[i]]);
}
/*vi loc(n);
for (int i=0; i<n; i++) {
loc[s[i]]=i;
}
for (int i=0; i<n-1; i++) {
p[i]=loc[i];
q[i]=i;
swap(loc[i],loc[s[i]]);
swap(s[i],s[loc[s[i]]]);
}*/
assert(check(n,ss,n-1,x,y,p,q));
return n-1;
}
# | 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... |