# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1108061 | Aviansh | Sorting (IOI15_sorting) | C++17 | 107 ms | 77700 KiB |
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[]) {
int be[n];
iota(be,be+n,0);
int ber[m][n];
for(int i = m-1;i>=0;i--){
swap(be[x[i]],be[y[i]]);
for(int j = 0;j<n;j++){
ber[i][be[j]]=j;
}
}
int r = 0;
for(int i = 0;i<n;i++){
swap(s[x[i]],s[y[i]]);
int ind = find(s,s+n,i)-s;
swap(s[ind],s[ber[r+1][i]]);
assert(ber[r+1][i]==i);
p[r]=ind;
q[r]=(ber[r+1][i]);
r++;
}
assert(r<=m);
for(;r<m;r++){
p[r]=0;
q[r]=0;
swap(s[x[r]],s[y[r]]);
}
for(int i = 0;i<n;i++){
assert(s[i]==i);
}
return r;
}
Compilation message (stderr)
# | 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... |