# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
804321 | _martynas | Sorting (IOI15_sorting) | C++11 | 1077 ms | 532 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 tryFindSwapPairs(const int N, int S[], const int M, int X[], int Y[], int P[], int Q[]) {
for (int i = 0; i < M; i++) P[i] = Q[i] = 0;
int T[N];
for (int i = 0; i < N; i++) T[i] = S[i];
for (int i = 0; i < M; i++) swap(T[X[i]], T[Y[i]]);
int where[N];
for (int i = 0; i < N; i++) where[T[i]] = i;
vector<pair<int, int>> swap_list;
for (int i = 0; i < N; i++) {
if (T[i] != i) {
swap_list.emplace_back(i, T[i]);
int a = i, b = where[i];
swap(where[T[a]], where[T[b]]);
swap(T[a], T[b]);
}
}
for (int i = 0; i < N; i++) T[i] = S[i];
for (int i = 0; i < N; i++) where[T[i]] = i;
for (int i = 0; i < (int)swap_list.size(); i++) {
swap(where[T[X[i]]], where[T[Y[i]]]);
swap(T[X[i]], T[Y[i]]);
int a = where[swap_list[i].first], b = where[swap_list[i].second];
P[i] = a;
Q[i] = b;
swap(where[T[a]], where[T[b]]);
# | 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... |