# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210933 | autumn_eel | Sorting (IOI15_sorting) | C++14 | 116 ms | 18040 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>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
int s[3000],spos[3000];
int p[3000],ppos[3000];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
if(is_sorted(S,S+N))return 0;
for(int R=1;R<=N;R++){
rep(i,N)p[i]=i,s[i]=S[i];
for(int i=R-1;i>=0;i--){
swap(p[X[i]],p[Y[i]]);
}
rep(i,N){
ppos[p[i]]=i;
spos[s[i]]=i;
}
int g=0;
rep(i,R){
swap(p[X[i]],p[Y[i]]);
swap(ppos[p[X[i]]],ppos[p[Y[i]]]);
swap(s[X[i]],s[Y[i]]);
swap(spos[s[X[i]]],spos[s[Y[i]]]);
while(g<N&&spos[g]==ppos[g])g++;
if(g==N){
P[i]=Q[i]=0;continue;
}
int a=spos[g],b=ppos[g];
P[i]=a;Q[i]=b;
swap(s[a],s[b]);
swap(spos[s[a]],spos[s[b]]);
}
rep(i,N)assert(p[i]==i);
bool ok=true;
rep(i,N){
if(s[i]!=i)ok=false;
}
if(ok){
return R;
}
}
return -1;
}
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... |