답안 #158849

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158849 2019-10-19T06:43:19 Z georgerapeanu 중앙값 배열 (balkan11_medians) C++11
100 / 100
130 ms 12792 KB
#include <cstdio>
#include <set>

using namespace std;

int n;
int a[200005];
int b[100005];
set<int> s;

int main(){

    scanf("%d",&n);

    for(int i = 1;i < 2 * n;i++){
        s.insert(i);
    }

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

    a[1] = b[1];
    s.erase(a[1]);
    
    for(int i = 2;i <= n;i++){
        if(b[i - 1] > b[i]){
            if(s.count(b[i])){
                a[i * 2 - 2] = b[i];s.erase(a[i * 2 - 2]);
                a[i * 2 - 1] = *s.begin();s.erase(a[i * 2 - 1]);
            }
            else{
                a[i * 2 - 2] = *s.begin();s.erase(a[i * 2 - 2]);
                a[i * 2 - 1] = *s.begin();s.erase(a[i * 2 - 1]);
            }
        }
        else if(b[i - 1] == b[i]){
            a[i * 2 - 2] = *s.begin();s.erase(a[i * 2 - 2]);
            a[i * 2 - 1] = *s.rbegin();s.erase(a[i * 2 - 1]);
        }
        else{
            if(s.count(b[i])){
                a[i * 2 - 2] = b[i];s.erase(a[i * 2 - 2]);
                a[i * 2 - 1] = *s.rbegin();s.erase(a[i * 2 - 1]);
            }
            else{
                a[i * 2 - 2] = *s.rbegin();s.erase(a[i * 2 - 2]);
                a[i * 2 - 1] = *s.rbegin();s.erase(a[i * 2 - 1]);
            }
        }
    }

    for(int i = 1;i < 2 * n;i++){
        printf("%d ",a[i]);
    }

    return 0;
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
medians.cpp:20:14: 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 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 252 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 9 ms 1276 KB Output is correct
4 Correct 18 ms 2296 KB Output is correct
5 Correct 37 ms 4216 KB Output is correct
6 Correct 79 ms 8184 KB Output is correct
7 Correct 130 ms 12792 KB Output is correct