# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
985116 | LucaIlie | 정렬하기 (IOI15_sorting) | C++17 | 202 ms | 25376 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sorting.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
int t[MAX_N], perm[MAX_N], vis[MAX_N], pos[MAX_N];
vector<pair<int, int>> sol;
int getR( int n, int s[], int k, int x[], int y[], int p[], int q[] ) {
for ( int i = 0; i < n; i++ )
t[i] = i, pos[i] = i;
for ( int i = 0; i < k; i++ ) {
swap( t[pos[x[i]]], t[pos[y[i]]] );
swap( pos[x[i]], pos[y[i]] );
}
for ( int i = 0; i < n; i++ )
perm[t[i]] = s[i];//, printf( "%d ", t[i] );
//printf( "\n\n" );
for ( int i = 0; i < n; i++ )
vis[i] = false;
sol.clear();
for ( int i = 0; i < n; i++ ) {
//printf( "%d ", perm[i] );
if ( vis[i] )
continue;
int j = i;
vector<pair<int, int>> v;
do {
vis[j] = true;
if ( perm[j] != j && j != i )
v.push_back( { j, perm[j] } );
j = perm[j];
} while ( j != i );
//reverse( v.begin(), v.end() );
for ( pair<int, int> swp: v )
sol.push_back( swp );
}
//printf( "\n" );
return sol.size();
}
int findSwapPairs( int n, int s[], int m, int x[], int y[], int p[], int q[] ) {
int l = -1, r = m;
while ( r - l > 1 ) {
int k = (l + r) / 2;
int rr = getR( n, s, k, x, y, p, q );
//printf( "%d %d\n", k, rr );
if ( rr > k )
l = k;
else
r = k;
}
getR( n, s, r, x, y, p, q );
for ( int i = 0; i < n; i++ )
pos[s[i]] = i;
for ( int i = 0; i < r; i++ ) {
//for ( int j = 0; j < n; j++ )
// printf( "%d ", pos[j] );
//printf( "\n" );
swap( pos[s[x[i]]], pos[s[y[i]]] );
swap( s[x[i]], s[y[i]] );
//for ( int j = 0; j < n; j++ )
// printf( "%d ", pos[j] );
//printf( "\n" );
if ( i < sol.size() ) {
//printf( "%d %d\n", sol[i].first, sol[i].second );
p[i] = pos[sol[i].first];
q[i] = pos[sol[i].second];
swap( pos[sol[i].first], pos[sol[i].second] );
swap( s[p[i]], s[q[i]] );
} else {
p[i] = 0;
q[i] = 0;
}
//for ( int j = 0; j < n; j++ )
// printf( "%d ", s[j] );
//printf( "\n\n" );
}
//for ( int i = 0; i < n; i++ )
// cout << s[i] << "\n";
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... |