Submission #31987

# Submission time Handle Problem Language Result Execution time Memory
31987 2017-09-20T20:59:36 Z chonka medians (balkan11_medians) C++
100 / 100
33 ms 4552 KB
#include<iostream>
#include<stdio.h>
using namespace std ;

#define MAXN 200007

int n ;
int a[ MAXN ] ;
int ans[ MAXN ] ;
int type[ MAXN ] ;

bool used[ MAXN ] ;

void input ( ) {
    scanf ( "%d" , &n ) ;
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        scanf ( "%d" , &a[ i ] ) ;
    }
}


void solve ( ) {
    int i ;
    for ( i = 1 ; i <= n ; i ++ ) {
        if ( used[ a[ i ] ] == false ) {
            ans[ 2 * i - 1 ] = a[ i ] ;
        }
        used[ a[ i ] ] = true ;
        if ( i != 1 ) {
            if ( a[ i ] > a[ i - 1 ] ) {
                type[ 2 * i - 1 ] = 1 ;
                type[ 2 * i - 2 ] = 1 ;
            }
            else if ( a[ i ] < a[ i - 1 ] ) {
                type[ 2 * i - 1 ] = -1 ;
                type[ 2 * i - 2 ] = -1 ;
            }
            else {
                type[ 2 * i - 1 ] = 1 ;
                type[ 2 * i - 2 ] = -1 ;
            }
        }
    }
    int l , r;
    l = 1 ;
    r = 2 * n - 1 ;
    for ( i = 1 ; i <= 2 * n - 1 ; i ++ ) {
        if ( ans[ i ] != 0 ) {
            printf ( "%d" , ans[ i ] ) ;
        }
        else {
            if ( type[ i ] == -1 ) {
                while ( used[ l ] == true ) { l ++ ; }
                used[ l ] = true ;
                printf ( "%d" , l ) ;
            }
            else {
                while ( used[ r ] == true ) { r -- ; }
                used[ r ] = true ;
                printf ( "%d" , r ) ;
            }
        }
        if ( i == 2 * n - 1 ) { printf ( "\n" ) ; }
        else { printf ( " " ) ; }
    }
}


int main ( ) {
    input ( ) ;
    solve ( ) ;
    return 0 ;
}

Compilation message

medians.cpp: In function 'void input()':
medians.cpp:15:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ( "%d" , &n ) ;
                         ^
medians.cpp:18:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ( "%d" , &a[ i ] ) ;
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4552 KB Output is correct
2 Correct 0 ms 4552 KB Output is correct
3 Correct 0 ms 4552 KB Output is correct
4 Correct 0 ms 4552 KB Output is correct
5 Correct 0 ms 4552 KB Output is correct
6 Correct 0 ms 4552 KB Output is correct
7 Correct 0 ms 4552 KB Output is correct
8 Correct 0 ms 4552 KB Output is correct
9 Correct 0 ms 4552 KB Output is correct
10 Correct 0 ms 4552 KB Output is correct
11 Correct 0 ms 4552 KB Output is correct
12 Correct 0 ms 4552 KB Output is correct
13 Correct 0 ms 4552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4552 KB Output is correct
2 Correct 0 ms 4552 KB Output is correct
3 Correct 3 ms 4552 KB Output is correct
4 Correct 6 ms 4552 KB Output is correct
5 Correct 9 ms 4552 KB Output is correct
6 Correct 19 ms 4552 KB Output is correct
7 Correct 33 ms 4552 KB Output is correct