# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1053713 | XJP12 | Sorting (IOI15_sorting) | C++14 | 2 ms | 348 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 <bits/stdc++.h>
#include "sorting.h"
using namespace std;
typedef vector<int> vi;
int findSwapPairs(int n, int s[], int m, int x[], int y[], int p[], int q[]) {
int r=0;
bool ban=true;
for(int i=0; i<n; i++){
if(s[i]!=i){
ban=false;
break;
}
}
if (ban) return 0;
if(y[0]==1){
for(int i=0; i<n; i++){
swap(s[1], s[0]);
r++;
/*for(int j=0; j<n; j++){
cout<<s[j]<<" ";
}*/
// cout<<endl;
ban=true;
for(int j=0; j<n; j++){
if(s[j]!=j){
ban=false;
break;
}
}
if (ban) break;
for(int j=0; j<n; j++){
if(s[j]==i){
if(s[i]==0 && i==1){
p[r-1]=j;
q[r-1]=i-1;
swap(s[i-1], s[j]);
}else{
p[r-1]=j;
q[r-1]=i;
swap(s[i], s[j]);
}
break;
}
}
/* for(int j=0; j<n; j++){
cout<<s[j]<<" ";
}
cout<<endl<<endl;*/
}
if(s[1]!=1 && s[0]!=0){
p[r]=0;
q[r]=1;
r++;
}
/*for(int i=0; i<r; i++){
cout<<p[i]<<" "<<q[i]<<endl;
}*/
}else{
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
if(s[j]==i && j!=i){
r++;
p[r-1]=j;
q[r-1]=i;
swap(s[i], s[j]);
break;
}
}
/* for(int j=0; j<n; j++){
cout<<s[j]<<" ";
}
cout<<endl;*/
}
/* for(int i=0; i<r; i++){
cout<<p[i]<<" "<<q[i]<<endl;
}*/
}
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... |