# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1090666 | owoovo | Sorting (IOI15_sorting) | C++17 | 1 ms | 860 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 u=1;
for(int i=0;i<M;i++)if(X[i]!=0||Y[i]!=0)u=0;
int ans=0,vis[110]={0};
if(u==1){
for(int i=0;i<N;i++){
if(vis[i]||S[i]==i)continue;
int now=S[i];
vis[i]=1;
while(now!=i){
vis[now]=1;
P[ans]=now;
Q[ans]=i;
now=S[now];
ans++;
}
}
return ans;
}else{
int p[110];
for(int i=0;i<N;i++){
if(vis[i]||S[i]==i)continue;
int now=S[i];
vis[i]=1;
while(now!=i){
//cout<<now<<" "<<i<<"\n";
ans++;
vis[now]=1;
if(now==0||now==1){
P[ans-1]=now^(ans%2);
}else{
P[ans-1]=now;
}
if(i==0||i==1){
Q[ans-1]=i^(ans%2);
}else{
Q[ans-1]=i;
}
now=S[now];
}
}
if(ans%2==1){
P[ans]=0;
Q[ans]=0;
ans++;
}
return ans;
}
}
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... |