이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#include "sorting.h"
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
auto check = [&](int R) {
vector<int> s(N), where(N), where_f(N);
REP(i, N) s[i] = S[i];
auto f = s;
REP(i, R) swap(f[X[i]], f[Y[i]]);
REP(i, N) {
where[S[i]] = i;
where_f[f[i]] = i;
}
int j = 0;
REP(i, R) P[i] = Q[i] = 0;
REP(i, R) {
int &p = s[X[i]], &q = s[Y[i]];
swap(p, q);
swap(where[p], where[q]);
while(j < N) {
int &a = where[j], &x = where_f[j];
int &b = where[f[j]], &y = where_f[f[j]];
j++;
if(a == b) continue;
P[i] = a, Q[i] = b;
swap(a, b), swap(s[a], s[b]);
swap(x, y), swap(f[x], f[y]);
break;
}
}
REP(i, N) if(i != s[i]) return false;
return true;
};
int l = 0, r = M;
while(l < r) {
int m = (l + r) / 2;
if(check(m))
r = m;
else
l = m + 1;
}
check(l);
return l;
}
# | 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... |