# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
419217 | someone | 정렬하기 (IOI15_sorting) | C++14 | 209 ms | 25752 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 <bits/stdc++.h>
#include "sorting.h"
//#define int long long
using namespace std;
const int N = 2e5 + 10, M = N * 3;
int n, a[N], b[N], s[M][2], pos[N];
int dicho(int deb, int fin) {
if(deb + 1 == fin)
return deb;
int med = (deb + fin) / 2 - 1;
for(int i = 0; i < n; i++)
b[i] = a[i];
for(int i = 0; i < med; i++)
swap(b[s[i][0]], b[s[i][1]]);
int t = 0;
for(int i = 0; i < n; i++) {
while(b[i] != i) {
t++;
swap(b[i], b[b[i]]);
}
}
if(t <= med)
return dicho(deb, med+1);
return dicho(med+1, fin);
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
for(int i = 0; i < n; i++)
a[i] = S[i];
for(int i = 0; i < M; i++) {
s[i][0] = X[i];
s[i][1] = Y[i];
}
int etape = dicho(0, M);
for(int i = 0; i < etape; i++)
P[i] = Q[i] = 0;
for(int i = 0; i < n; i++)
b[i] = a[i];
for(int i = 0; i < etape; i++)
swap(b[s[i][0]], b[s[i][1]]);
for(int i = 0; i < n; i++)
pos[a[i]] = i;
int j = 0;
for(int i = 0; i < n; i++) {
while(b[i] != i) {
swap(pos[a[s[j][0]]], pos[a[s[j][1]]]);
swap(a[s[j][0]], a[s[j][1]]);
P[j] = pos[b[i]];
Q[j] = pos[b[b[i]]];
swap(pos[b[i]], pos[b[b[i]]]);
swap(a[pos[b[i]]], a[pos[b[b[i]]]]);
swap(b[i], b[b[i]]);
j++;
}
}
return etape;
}
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... |