답안 #51811

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51811 2018-06-21T09:07:44 Z someone_aa 중앙값 배열 (balkan11_medians) C++17
100 / 100
31 ms 3200 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200100;
int a[2*maxn], b[maxn], n;
int minvalue, maxvalue;
bool visited[2*maxn];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>b[i];
    }

    minvalue = 1;
    maxvalue = 2*n-1;

    visited[b[1]]=true;
    a[1] = b[1];
    while(visited[minvalue]) minvalue++;
    while(visited[maxvalue]) maxvalue--;

    for(int i=2;i<=n;i++) {
        if(b[i] == b[i-1]) {
            a[2*(i-1)] = minvalue;
            visited[minvalue] = true;
            while(visited[minvalue]) minvalue++;
            a[2*(i-1)+1] = maxvalue;
            visited[maxvalue] = true;
            while(visited[maxvalue]) maxvalue--;
        }
        else if(b[i] < b[i-1]) {
            if(visited[b[i]]) {
                a[2*(i-1)] = minvalue;
                visited[minvalue] = true;
                while(visited[minvalue]) minvalue++;
                a[2*(i-1)+1] = minvalue;
                visited[minvalue] = true;
                while(visited[minvalue]) minvalue++;
            }
            else {
                a[2*(i-1)] = b[i];
                visited[b[i]] = true;
                while(visited[minvalue]) minvalue++;
                while(visited[maxvalue]) maxvalue--;
                a[2*(i-1)+1] = minvalue;
                visited[minvalue] = true;
                while(visited[minvalue]) minvalue++;
            }
        }
        else if(b[i] > b[i-1]) {
            if(visited[b[i]]) {
                a[2*(i-1)] = maxvalue;
                visited[maxvalue] = true;
                while(visited[maxvalue]) maxvalue--;
                a[2*(i-1)+1] = maxvalue;
                visited[maxvalue] = true;
                while(visited[maxvalue]) maxvalue--;
            }
            else {
                a[2*(i-1)] = b[i];
                visited[b[i]] = true;
                while(visited[maxvalue]) maxvalue--;
                while(visited[minvalue]) minvalue++;
                a[2*(i-1)+1] = maxvalue;
                visited[maxvalue] = true;
                while(visited[maxvalue]) maxvalue--;
            }
        }
    }

    for(int i=1;i<=2*n-1;i++) {
        cout<<a[i]<<" ";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 532 KB Output is correct
7 Correct 2 ms 672 KB Output is correct
8 Correct 2 ms 672 KB Output is correct
9 Correct 2 ms 672 KB Output is correct
10 Correct 1 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
13 Correct 2 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 672 KB Output is correct
2 Correct 4 ms 736 KB Output is correct
3 Correct 5 ms 752 KB Output is correct
4 Correct 6 ms 1024 KB Output is correct
5 Correct 11 ms 1444 KB Output is correct
6 Correct 20 ms 2304 KB Output is correct
7 Correct 31 ms 3200 KB Output is correct