# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
789998 | PoonYaPat | Sorting (IOI15_sorting) | C++14 | 1 ms | 468 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;
typedef pair<int,int> pii;
int n,m,a[200005],pos[200005];
vector<pii> v;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n=N; m=M;
for (int i=0; i<n; ++i) a[i]=S[i], pos[a[i]]=i;
if (X[0]==0 && Y[0]==0) {
for (int i=n-1; i>=0; --i) {
if (i!=pos[i]) {
v.push_back(pii(i,pos[i]));
int bef=a[i];
a[pos[i]]=a[i];
a[i]=i;
pos[bef]=pos[i];
pos[i]=i;
}
}
} else {
for (int i=n-1; i>=2; --i) {
if (i!=pos[i]) {
swap(a[0],a[1]);
pos[a[0]]=0;
pos[a[1]]=1;
v.push_back(pii(i,pos[i]));
int bef=a[i];
a[pos[i]]=a[i];
a[i]=i;
pos[bef]=pos[i];
pos[i]=i;
}
}
if (a[0]==1 && a[1]==0) v.push_back(pii(0,0));
}
for (int i=0; i<v.size(); ++i) P[i]=v[i].first, Q[i]=v[i].second;
return v.size();
}
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... |