# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
285115 | SamAnd | 정렬하기 (IOI15_sorting) | C++17 | 515 ms | 30344 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
const int N = 200005 * 3;
int n, m;
int S[N];
int X[N], Y[N];
int a[N];
int b[N], bb[N];
int uu[N];
int u[N];
bool c[N];
int P[N], Q[N];
bool stg(int q)
{
for (int i = 0; i < n; ++i)
{
a[i] = S[i];
b[i] = i;
bb[i] = i;
c[i] = false;
}
for (int i = 0; i < q; ++i)
{
swap(b[bb[X[i]]], b[bb[Y[i]]]);
swap(bb[X[i]], bb[Y[i]]);
}
for (int i = 0; i < n; ++i)
{
uu[b[i]] = i;
}
for (int i = 0; i < n; ++i)
{
u[i] = uu[a[i]];
}
for (int i = 0; i < n; ++i)
{
b[i] = i;
bb[i] = i;
}
int ans = 0;
for (int i = 0; i < n; ++i)
{
int x = i;
if (c[x])
continue;
vector<int> v;
c[x] = true;
while (1)
{
x = u[x];
if (c[x])
break;
v.push_back(x);
c[x] = true;
}
for (int j = 0; j < sz(v); ++j)
{
swap(b[bb[X[ans]]], b[bb[Y[ans]]]);
swap(bb[X[ans]], bb[Y[ans]]);
swap(a[i], a[v[j]]);
P[ans] = b[i];
Q[ans] = b[v[j]];
ans++;
}
}
while (ans < q)
{
P[ans] = 0;
Q[ans] = 0;
ans++;
}
return ans <= q;
}
int findSwapPairs(int N_, int S[], int M_, int X[], int Y[], int P[], int Q[])
{
n = N_;
m = M_;
for (int i = 0; i < n; ++i)
{
::S[i] = S[i];
}
for (int i = 0; i < m; ++i)
{
::X[i] = X[i];
::Y[i] = Y[i];
}
int l = 0, r = m;
int ans = -1;
while (l <= r)
{
int mid = (l + r) / 2;
if (stg(mid))
{
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
assert(ans != -1);
stg(ans);
for (int i = 0; i < ans; ++i)
{
P[i] = ::P[i];
Q[i] = ::Q[i];
}
for (int i = 0; i < ans; ++i)
{
swap(S[X[i]], S[Y[i]]);
swap(S[P[i]], S[Q[i]]);
}
for (int i = 0; i < n; ++i)
{
if (S[i] != i)
{
assert(false);
}
}
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... |