#include "sorting.h"
#include<bits/stdc++.h>
using namespace std;
int n , m , a [502] , x [20004] , y [20004] , dis [502][20004];
int findSwapPairs(int N, int S[], int M, int X[], int Y[], int P[], int Q[]) {
n = N;
for ( int i = 1 ; i <= n ; i ++ )
{
a [i] = S [i];
a [i] ++;
}
m = M;
for ( int i = 0 ; i < m ; i ++ )
{
x [i] = X [i] , y [i] = Y [i];
x [i] ++ , y [i] ++;
}
for ( int i = 1 ; i <= n ; i ++ ) dis [i][m] = i;
for ( int j = m - 1 ; j >= 0 ; j -- )
{
for ( int i = 1 ; i <= n ; i ++ ) dis [i][j] = dis [i][ j + 1 ];
swap ( dis [ x [j] ][j] , dis [ y [j] ][j] );
}
int r = 0;
for ( int i = 1 ; i <= m ; i ++ )
{
swap ( a [ x [ i - 1 ] ] , a [ y [ i - 1 ] ] );
P [ i - 1 ] = -1 , Q [ i - 1 ] = -1;
for ( int j = 1 ; j <= n ; j ++ )
{
if ( dis [j][i] != a [j] )
{
int wr;
for ( int z = 1 ; z <= n ; z ++ )
{
if ( a [z] == dis [j][i] )
{
wr = z;
break;
}
}
P [ i - 1 ] = j - 1 , Q [ i - 1 ] = wr - 1;
swap ( a [j] , a [wr] );
r ++;
break;
}
}
if ( P [ i - 1 ] == -1 )
{
P [ i - 1 ] = 0;
Q [ i - 1 ] = 0;
}
}
return r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
4748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
4748 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |