# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
434632 | dxz05 | Sorting (IOI15_sorting) | C++14 | 4 ms | 588 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;
const int MAXN = 1024;
int a[MAXN];
vector<pair<int, int>> ans;
void Do(int i, int j){
swap(a[i], a[j]);
ans.emplace_back(i, j);
}
void Do2(){
swap(a[0], a[1]);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
for (int i = 0; i < N; i++) a[i] = S[i];
Do2();
for (int i = 2; i < N; i++){
if (a[i] == 0){
for (int j = 0; j < 2; j++){
if (a[j] > 1){
Do(i, j);
break;
}
}
}
}
Do2();
for (int i = 2; i < N; i++){
if (a[i] == 1){
for (int j = 0; j < 2; j++){
if (a[j] > 1){
Do(i, j);
break;
}
}
}
}
for (int i = 2; i < N; i++){
int j = i;
while (j < N && a[j] != i) j++;
j--;
if (i != j){
Do(i, j);
Do2();
}
}
for (int i = 0; i < 10; i++){
Do(0, 1);
Do2();
}
for (int i = 0; i < ans.size(); i++){
bool ok = true;
for (int j = 0; j < N; j++){
if (S[j] != j) ok = false;
}
if (ok) return i;
P[i] = ans[i].first;
Q[i] = ans[i].second;
swap(S[0], S[1]);
swap(S[P[i]], S[Q[i]]);
}
return ans.size();
}
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... |