# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
135285 | Boxworld | Sorting (IOI15_sorting) | C++14 | 17 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 R=0;
for (int i=0;i<N;i++)
for (int j=i+1;j<N;j++)
if (S[i]>S[j])R++;
if (R==0)return 0;
for (int i=0;i<M;i++){
int p1,p2,start=0,ok=1;
for (int j=0;j<N;j++)
if (S[j]==X[i]){p1=j;break;}
for (int j=0;j<N;j++)
if (S[j]==Y[i]){p2=j;break;}
// printf("SWAP**:S[%d]=%d S[%d]=%d\nNOW:",p1,S[p1],p2,S[p2]);
swap(S[p1],S[p2]);
// for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n");
if (p1+p2==1&&S[p1]+S[p2]==1)start=2;
for (int j=start;j<N-1;j++)
if (S[j]!=j){
P[i]=j;Q[i]=S[j];
// printf("SWAP%d:S[%d]=%d S[%d]=%d\nNOW:",i,j,S[j],S[j],S[S[j]]);
swap(S[j],S[S[j]]);
// for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n");
ok=0;
break;
}
if (ok){
if (S[0]>S[1]){
P[i]=0;Q[i]=1;
// printf("SWAP%d:S[%d]=%d S[%d]=%d\nNOW:",i,0,S[0],1,S[1]);
swap(S[0],S[1]);
// for (int i=0;i<N;i++)printf("%d ",S[i]);printf("\n");
return i;
}else {
P[i]=0;
Q[i]=0;
return i;
}
}
}
}
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... |