Submission #620966

# Submission time Handle Problem Language Result Execution time Memory
620966 2022-08-03T10:40:23 Z mdn2002 Sorting (IOI15_sorting) C++14
54 / 100
36 ms 31676 KB
#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 - 1 ];
        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 ++ )
    {
        int f = 0;
        for ( int i = 1 ; i <= n ; i ++ ) 
        {
            if ( a [i] != i ) f = 1;
        }
        if ( f == 0 ) return r;
        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;
            r ++;
        }
    }
    return r;
}


Compilation message

sorting.cpp: In function 'int findSwapPairs(int, int*, int, int*, int*, int*, int*)':
sorting.cpp:31:19: warning: declaration of 'i' shadows a previous local [-Wshadow]
   31 |         for ( int i = 1 ; i <= n ; i ++ )
      |                   ^
sorting.cpp:28:15: note: shadowed declaration is here
   28 |     for ( int i = 1 ; i <= m ; i ++ )
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 1748 KB Output is correct
4 Correct 1 ms 1876 KB Output is correct
5 Correct 2 ms 1876 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 1876 KB Output is correct
11 Correct 1 ms 1876 KB Output is correct
12 Correct 2 ms 1748 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 1748 KB Output is correct
16 Correct 1 ms 1876 KB Output is correct
17 Correct 2 ms 1876 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 28 ms 29900 KB Output is correct
22 Correct 31 ms 29480 KB Output is correct
23 Correct 36 ms 31596 KB Output is correct
24 Correct 33 ms 30252 KB Output is correct
25 Correct 30 ms 31676 KB Output is correct
26 Correct 29 ms 29556 KB Output is correct
27 Correct 28 ms 29268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 4836 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 4836 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -