답안 #51809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51809 2018-06-21T08:57:13 Z someone_aa 중앙값 배열 (balkan11_medians) C++17
85 / 100
54 ms 3212 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++;
                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--;
                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 3 ms 376 KB Output is correct
3 Correct 3 ms 436 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 2 ms 672 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 2 ms 672 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 3 ms 672 KB Output is correct
13 Correct 3 ms 672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 672 KB Not a permutation
2 Correct 4 ms 672 KB Output is correct
3 Correct 6 ms 780 KB Output is correct
4 Incorrect 8 ms 1036 KB Not a permutation
5 Correct 14 ms 1420 KB Output is correct
6 Incorrect 36 ms 2316 KB Not a permutation
7 Correct 54 ms 3212 KB Output is correct