| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 99206 | eriksuenderhauf | 정렬하기 (IOI15_sorting) | C++11 | 748 ms | 30724 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "sorting.h"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
int n = 0, m = 0;
int x[MAXN], y[MAXN], p[MAXN], q[MAXN], sz[MAXN], ind2[MAXN];
int p2[MAXN], q2[MAXN], par[MAXN], a[MAXN], ind[MAXN];
int qry(int x) {
if (x == par[x]) return x;
return par[x] = qry(par[x]);
}
void join(int x, int y) {
x = qry(x), y = qry(y);
if (x == y) return;
if (sz[x] > sz[y]) swap(x, y);
sz[y] += sz[x];
par[x] = y;
}
bool solve(int cnt) {
for (int i = 0; i < n; i++)
par[i] = i, sz[i] = 1, ind[i] = i;
for (int i = 0; i < cnt; i++) {
swap(a[x[i]], a[y[i]]);
swap(ind[x[i]], ind[y[i]]);
}
for (int i = 0; i < n; i++)
join(i, a[i]);
vii ans;
int cnt2 = 0;
for (int i = 0; i < n; i++) {
if (qry(i) != i)
continue;
cnt2 += sz[i] - 1;
int nx = a[i], pr = i;
while (nx != i) {
ans.pb({ind[i], ind[nx]});
pr = nx;
nx = a[nx];
}
}
while (ans.size() < cnt)
ans.pb({0, 0});
for (int i = 0; i < n; i++)
ind[i] = i, ind2[i] = i;
for (int i = 0; i < cnt; i++) {
swap(ind2[ind[x[i]]], ind2[ind[y[i]]]);
swap(ind[x[i]], ind[y[i]]);
p[i] = ind2[ans[i].fi], q[i] = ind2[ans[i].se];
}
return (ans.size() == cnt);
}
void cp(int cnt) {
for (int i = 0; i < cnt; i++)
p2[i] = p[i], q2[i] = q[i];
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N, m = M;
int lo = 0, hi = n - 1, ans = -1;
for (int i = 0; i < m; i++)
x[i] = X[i], y[i] = Y[i];
while (lo <= hi) {
int mi = (lo + hi) / 2;
for (int i = 0; i < n; i++)
a[i] = S[i];
if (solve(mi)) {
hi = mi - 1, ans = mi;
cp(ans);
} else
lo = mi + 1;
}
for (int i = 0; i < ans; i++)
P[i] = p2[i], Q[i] = q2[i];
return ans;
}
컴파일 시 표준 에러 (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... | ||||
