| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 102713 | wxh010910 | 정렬하기 (IOI15_sorting) | C++17 | 224 ms | 18760 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "sorting.h"
using namespace std;
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
vector<bool> visit(N);
vector<int> after(N);
auto check = [&](int mid) {
for (int i = 0; i < N; ++i) {
after[i] = S[i];
visit[i] = false;
}
for (int i = 0; i < mid; ++i) {
swap(after[X[i]], after[Y[i]]);
}
int ans = 0;
for (int i = 0; i < N; ++i) {
if (!visit[i]) {
for (int j = i; ; j = after[j]) {
visit[j] = true;
if (!visit[after[j]]) {
P[ans] = i;
Q[ans] = after[j];
++ans;
} else {
break;
}
}
}
}
for (int i = ans; i < mid; ++i) {
P[i] = Q[i] = 0;
}
return ans <= mid;
};
int l = 0, r = N;
while (l < r) {
int mid = (l + r) >> 1;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
check(r);
vector<int> pos(N);
vector<int> to(N);
for (int i = 0; i < N; ++i) {
pos[i] = to[i] = i;
}
for (int i = r - 1; ~i; --i) {
P[i] = to[P[i]];
Q[i] = to[Q[i]];
swap(pos[X[i]], pos[Y[i]]);
to[pos[X[i]]] = X[i];
to[pos[Y[i]]] = Y[i];
}
return r;
}
컴파일 시 표준 에러 (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... | ||||
