# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
285160 | SamAnd | 정렬하기 (IOI15_sorting) | C++17 | 565 ms | 9960 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;
int n, m;
int a[N], b[N];
vector<int> g[N];
int c[N];
int k;
void dfs(int x)
{
c[x] = k;
for (int i = 0; i < g[x].size(); ++i)
{
int h = g[x][i];
if (!c[h])
dfs(h);
}
}
vector<int> v[N];
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)
b[i] = S[i];
for (int i = 0; i < n; ++i)
a[i] = S[i];
bool z = true;
for (int i = 0; i < n - 1; ++i)
{
if (a[i] > a[i + 1])
{
z = false;
break;
}
}
if (z)
return 0;
for (int i = 0; i < m; ++i)
{
P[i] = Q[i] = 0;
swap(a[X[i]], a[Y[i]]);
for (int x = 0; x < n; ++x)
g[x].clear();
for (int j = i + 1; j < m; ++j)
{
g[X[j]].push_back(Y[j]);
g[Y[j]].push_back(X[j]);
}
for (int x = 0; x < n; ++x)
c[x] = 0;
k = 0;
for (int x = 0; x < n; ++x)
{
if (!c[x])
{
++k;
dfs(x);
}
}
for (int i = 1; i <= k; ++i)
v[i].clear();
for (int x = 0; x < n; ++x)
v[c[x]].push_back(a[x]);
for (int i = 1; i <= k; ++i)
sort(all(v[i]));
for (int x = 0; x < n; ++x)
{
if (!binary_search(all(v[c[x]]), x))
{
vector<int> vv;
for (int y = 0; y < n; ++y)
{
if (c[y] == c[x])
vv.push_back(y);
}
int xx = -1;
for (int i = 0; i < v[c[x]].size(); ++i)
{
int u = v[c[x]][i];
if (!binary_search(all(vv), u))
{
for (int y = 0; y < n; ++y)
{
if (a[y] == u)
{
xx = y;
break;
}
}
break;
}
}
assert(xx != -1);
for (int y = 0; y < n; ++y)
{
if (a[y] == x)
{
swap(a[xx], a[y]);
P[i] = xx;
Q[i] = y;
break;
}
}
break;
}
}
z = true;
for (int i = 0; i < n - 1; ++i)
{
if (a[i] > a[i + 1])
{
z = false;
break;
}
}
if (z)
{
for (int j = 0; j <= i; ++j)
{
swap(b[X[j]], b[Y[j]]);
swap(b[P[j]], b[Q[j]]);
}
for (int i = 0; i < n; ++i)
{
if (b[i] != i)
{
assert(false);
}
}
return i;
}
}
assert(false);
return -1;
}
컴파일 시 표준 에러 (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... |