이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + 20;
int cnt[maxN];
bool cmp(int i, int j) {
return cnt[i] < cnt[j];
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
for (int i = 0; i < M; i++) {
cnt[X[i]]++;
cnt[Y[i]]++;
}
int len = 0;
for (int i = 0; ; i++) {
bool ok = true;
for (int j = 0; j < N; j++) {
if (S[j] != j) {
ok = false;
break;
}
}
if (ok) {
return len;
}
assert(i < M);
cnt[X[i]]--;
cnt[Y[i]]--;
swap(S[X[i]], S[Y[i]]);
vector<int> wrong;
for (int j = 0; j < N; j++) {
if (S[j] != j) {
wrong.push_back(j);
}
}
if (wrong.empty()) {
P[len] = 0;
Q[len] = 0;
}
else {
sort(wrong.begin(), wrong.end(), cmp);
P[len] = wrong[0];
for (int j = 0; j < N; j++) {
if (S[j] == wrong[0]) {
Q[len] = j;
break;
}
}
}
swap(S[P[len]], S[Q[len]]);
len++;
}
}
# | 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... |