# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1096509 | onlk97 | Sorting (IOI15_sorting) | C++14 | 17 ms | 604 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 r;
int a[N];
for (int i=0; i<N; i++) a[i]=S[i];
for (int i=0; i<M; i++){
swap(a[X[i]],a[Y[i]]);
bool vis[N];
for (int j=0; j<N; j++) vis[j]=0;
int cnt=0;
for (int j=0; j<N; j++){
if (vis[j]) continue;
cnt++;
int tp=j;
while (!vis[tp]){
vis[tp]=1;
tp=a[tp];
}
}
if (N-cnt<=i+1){
r=i+1;
break;
}
}
bool allsame=1;
for (int i=0; i<N; i++) if (S[i]!=i) allsame=0;
if (allsame) r=0;
for (int i=0; i<r; i++){
swap(S[X[i]],S[Y[i]]);
bool stillhave[N];
for (int j=0; j<N; j++) stillhave[j]=0;
for (int j=i+1; j<r; j++){
if (X[j]==Y[j]) continue;
stillhave[X[j]]=1; stillhave[Y[j]]=1;
}
int haha=-1;
for (int j=0; j<N; j++){
if (!stillhave[j]&&S[j]!=j) haha=j;
}
if (haha==-1){
P[i]=0; Q[i]=0;
continue;
}
for (int j=0; j<N; j++) if (S[j]==haha) P[i]=j;
Q[i]=haha;
swap(S[P[i]],S[Q[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... |