# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1075215 | ArthuroWich | Sorting (IOI15_sorting) | C++17 | 30 ms | 592 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;
vector<pair<int, int>> ans, xy, swaps;
bool check(vector<int> p, int x, int n) {
int s = 0;
vector<int> e = p;
vector<int> co(n, 0);
for (int i = 0; i < n; i++) {
co[p[i]] = i;
}
for (int i = 0; i < x; i++) {
swap(p[xy[i].first], p[xy[i].second]);
}
for (int i = 0; i < n; i++) {
if (p[i] == i) {
continue;
}
while(p[i] != i) {
int j = p[i];
swaps.push_back({co[i], co[j]});
swap(co[p[i]], co[p[j]]);
swap(p[i], p[j]);
s++;
}
}
while(swaps.size() < x) {
swaps.push_back({0, 0});
}
return s <= x;
}
int findSwapPairs(int n, int A[], int M, int X[], int Y[], int P[], int Q[]) {
vector<int> p(n);
for (int i = 0; i < n; i++) {
p[i] = A[i];
}
for (int i = 0; i < M; i++) {
xy.push_back({X[i], Y[i]});
}
for (int i = 0; i <= M; i++) {
swaps.clear();
if (check(p, i, n)) {
ans = swaps;
break;
}
}
for (int i = 0; i < ans.size(); i++) {
P[i] = ans[i].first;
Q[i] = ans[i].second;
}
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... |