Submission #626863

# Submission time Handle Problem Language Result Execution time Memory
626863 2022-08-11T22:03:03 Z chonka Swap (BOI16_swap) C++17
0 / 100
1000 ms 9724 KB
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;

const int MAXN = 2e5 + 7 ;

int n ;
int a[ MAXN ] , ans[ MAXN ] , pos[ MAXN ] ;
bool used[ MAXN ] , right[ MAXN ] ;

set < int > s[ MAXN ] ;

void solve ( ) {
    cin >> n ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        cin >> a[ i ] ;
        pos[ a[ i ] ] = i ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        s[ i ].insert ( a[ i ] ) ;
        if ( 2 * i <= n ) {
            s[ i ].insert ( a[ 2 * i ] ) ;
        }
        if ( 2 * i + 1 <= n ) {
            s[ i ].insert ( a[ 2 * i + 1 ] ) ;
        }
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        int act = 0 ;
        while ( 1 ) {
            act = *s[ i ].begin ( ) ;
            s[ i ].erase ( act ) ;
            if ( used[ act ] == false ) { break ; }
        }
        ans[ i ] = act ;
        used[ act ] = true ;
        if ( pos[ act ] == 2 * i + 1 ) {
            for ( auto x : s[ i ] ) {
                s[ 2 * i ].insert ( x ) ;
                s[ 2 * i + 1 ].insert ( x ) ;
            }
        }
        else if ( pos[ act ] == 2 * i ) {
            for ( auto x : s[ i ] ) {
                s[ 2 * i ].insert ( x ) ;
            }
        }
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        cout << ans[ i ] << " " ;
    }
    cout << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; // cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Execution timed out 1081 ms 9724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Execution timed out 1081 ms 9724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Execution timed out 1081 ms 9724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Execution timed out 1081 ms 9724 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Execution timed out 1081 ms 9724 KB Time limit exceeded
3 Halted 0 ms 0 KB -