# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
31986 | chonka | 중앙값 배열 (balkan11_medians) | C++98 | 29 ms | 4552 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 {
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 ;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |