답안 #24815

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24815 2017-06-14T12:04:44 Z Extazy 중앙값 배열 (balkan11_medians) C++14
100 / 100
29 ms 3776 KB
/*
example test starts
1

5
1 3 3 4 5
example test ends
*/
#include <bits/stdc++.h>

using namespace std;

const int N = (2e5) + 7;

int n,a[N],b[N];
int up,down;
bool used[N];

void go_up() {
    while(used[up]) --up;
    used[up]=true;
}

void go_down() {
    while(used[down]) ++down;
    used[down]=true;
}

int main() {
    int tests,current_case;
    int i;

    tests=1;
    //scanf("%d", &tests);
    for(current_case=1;current_case<=tests;current_case++) {
        scanf("%d", &n);
        for(i=1;i<=n;i++) {
            scanf("%d", &b[i]);
        }
        memset(used,0,sizeof(used));
        down=0;
        up=2*n;
        used[down]=used[up]=true;
        a[1]=b[1];
        used[b[1]]=true;
        for(i=2;i<=n;i++) {
            if(b[i]==b[i-1]) {
                go_up();
                a[2*(i-1)]=up;
                go_down();
                a[2*(i-1)+1]=down;
            }
            else if(b[i]>b[i-1]) {
                if(!used[b[i]]) {
                    used[b[i]]=true;
                    a[2*(i-1)]=b[i];
                    go_up();
                    a[2*(i-1)+1]=up;
                }
                else {
                    go_up();
                    a[2*(i-1)]=up;
                    go_up();
                    a[2*(i-1)+1]=up;
                }
            }
            else {
                if(!used[b[i]]) {
                    used[b[i]]=true;
                    a[2*(i-1)]=b[i];
                    go_down();
                    a[2*(i-1)+1]=down;
                }
                else {
                    go_down();
                    a[2*(i-1)]=down;
                    go_down();
                    a[2*(i-1)+1]=down;
                }
            }
        }
    }
    for(i=1;i<2*n;i++) {
        if(i>1) printf(" ");
        printf("%d", a[i]);
    }

    return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:36:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &n);
                        ^
medians.cpp:38:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &b[i]);
                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3776 KB Output is correct
2 Correct 0 ms 3776 KB Output is correct
3 Correct 0 ms 3776 KB Output is correct
4 Correct 0 ms 3776 KB Output is correct
5 Correct 0 ms 3776 KB Output is correct
6 Correct 0 ms 3776 KB Output is correct
7 Correct 0 ms 3776 KB Output is correct
8 Correct 0 ms 3776 KB Output is correct
9 Correct 0 ms 3776 KB Output is correct
10 Correct 0 ms 3776 KB Output is correct
11 Correct 0 ms 3776 KB Output is correct
12 Correct 0 ms 3776 KB Output is correct
13 Correct 0 ms 3776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 3776 KB Output is correct
2 Correct 0 ms 3776 KB Output is correct
3 Correct 3 ms 3776 KB Output is correct
4 Correct 6 ms 3776 KB Output is correct
5 Correct 13 ms 3776 KB Output is correct
6 Correct 23 ms 3776 KB Output is correct
7 Correct 29 ms 3776 KB Output is correct