# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1053805 | Osplei | Sorting (IOI15_sorting) | C++17 | 1 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 "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
typedef pair <ll, ll> LL;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
vector <int> orden;
int ans = 0, pos = 0;
for (int i = 0; i < N; i++) {
orden.pb(S[i]);
}
sort(orden.begin(), orden.end());
if (N == 1) {
P[0] = 0;
Q[0] = 0;
return 0;
}
for (int i = 0; i < N; i++) {
if (orden[i] != S[i]) {
ans++;
swap(S[0], S[1]);
for (int j = i; j < N; j++) {
if (orden[i] == S[j]) {
swap(S[i], S[j]);
P[pos] = i;
Q[pos] = j;
pos++;
break;
}
}
P[pos] = 0;
Q[pos] = 0;
pos++;
}
}
for (int i = 0; i < N; i++) {
if (orden[i] != S[i]) {
ans++;
swap(S[0], S[1]);
for (int j = i; j < N; j++) {
if (orden[i] == S[j]) {
swap(S[i], S[j]);
P[pos] = i;
Q[pos] = j;
pos++;
break;
}
}
P[pos] = 0;
Q[pos] = 0;
pos++;
}
}
for (int i = 0; i < N; i++) {
if (orden[i] != S[i]) {
ans++;
swap(S[0], S[1]);
for (int j = i; j < N; j++) {
if (orden[i] == S[j]) {
swap(S[i], S[j]);
P[pos] = i;
Q[pos] = j;
pos++;
break;
}
}
P[pos] = 0;
Q[pos] = 0;
pos++;
}
}
if (S[0] > S[1]) {
ans++;
P[pos] = 0;
Q[pos] = 1;
pos++;
}
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... |