# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
552908 | elazarkoren | Sorting (IOI15_sorting) | C++17 | 1094 ms | 8088 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>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)
//#define int ll
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;
const int MAX_N = 2e5 + 5;
int x[MAX_N], y[MAX_N];
int n;
int cnt;
vi Compute(vi s) {
for (int i = 0; i < cnt; i++) swap(s[x[i]], s[y[i]]);
return s;
}
bool Ok(int N, int S[], int m, int X[], int Y[], int p[], int q[]) {
cnt = m;
vi s(n);
for (int i = 0; i < n; i++) s[i] = S[i], x[i] = X[i], y[i] = Y[i];
vi s2 = Compute(s);
int index = 0;
for (int i = 0; i < cnt; i++) {
swap(s[x[i]], s[y[i]]);
int v1 = 0, v2 = 0;
for (; index < n; index++) {
if (s2[index] == index) continue;
for (int j = index + 1; j < n; j++) {
if (s2[j] == index) {
v1 = s2[index], v2 = s2[j];
swap(s2[index], s2[j]);
}
}
index++;
break;
}
int ind1, ind2;
for (ind1 = 0; s[ind1] != v1; ind1++);
for (ind2 = 0; s[ind2] != v2; ind2++);
p[i] = ind1, q[i] = ind2;
swap(s[p[i]], s[q[i]]);
}
return is_sorted(all(s));
}
int findSwapPairs(int N, int S[], int m, int X[], int Y[], int p[], int q[]) {
n = N;
int begin = 0, end = n - 1, mid;
while (begin < end) {
mid = (begin + end) >> 1;
if (Ok(N, S, mid, X, Y, p, q)) {
end = mid;
} else begin = mid + 1;
}
Ok(N, S, end, X, Y, p, q);
return end;
}
//8
//3 5 6 2 1 7 0 4
//8
//0 1
//0 1
//0 1
//0 1
//0 1
//0 1
//0 1
//0 1
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... |