# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
105053 | Alexa2001 | 정렬하기 (IOI15_sorting) | C++17 | 722 ms | 29380 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int Nmax = 2e5 + 5;
bool used[Nmax];
int p[Nmax], P[Nmax], A[Nmax], wA[Nmax], B[Nmax], wB[Nmax], wp[Nmax];
vector< pair<int,int> > get_moves(int n, int p[])
{
int i;
for(i=0; i<n; ++i) used[i] = 0;
vector< pair<int,int> > mv;
for(i=0; i<n; ++i)
if(!used[i])
{
int x = i;
vector<int> cycle;
do
{
used[x] = 1;
cycle.push_back(x);
x = p[x];
}
while(!used[x]);
for(int j = 0; j + 1 < cycle.size(); ++j)
mv.push_back({p[cycle[j]], p[cycle[j+1]]});
}
return mv;
}
bool check(int n, int m, int S[], int x[], int y[], int op1[], int op2[])
{
int i;
for(i=0; i<n; ++i) p[i] = i, wp[i] = i;
for(i=0; i<m; ++i)
{
int id1, id2;
id1 = wp[x[i]]; id2 = wp[y[i]];
swap(wp[p[id1]], wp[p[id2]]);
swap(p[id1], p[id2]);
}
for(i=0; i<n; ++i) P[p[i]] = S[i];
auto o = get_moves(n, P);
if(o.size() > m) return 0;
o.resize(m);
for(i=0; i<n; ++i) A[i] = wA[i] = i, B[i] = S[i], wB[S[i]] = i;
for(i=0; i<m; ++i)
{
int id1, id2;
id1 = wA[x[i]]; id2 = wA[y[i]];
swap(wA[A[id1]], wA[A[id2]]);
swap(A[id1], A[id2]);
tie(id1, id2) = o[i];
id1 = wB[id1]; id2 = wB[id2];
op1[i] = A[id1];
op2[i] = A[id2];
swap(wB[B[id1]], wB[B[id2]]);
swap(B[id1], B[id2]);
}
return 1;
}
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[])
{
int st, dr, mid;
st = 0; dr = M;
while(st <= dr)
{
mid = (st + dr) / 2;
if(check(N, mid, S, X, Y, P, Q)) dr = mid - 1;
else st = mid + 1;
}
check(N, st, S, X, Y, P, Q);
return st;
}
컴파일 시 표준 에러 (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... |