답안 #31727

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31727 2017-09-03T00:23:34 Z simotion 중앙값 배열 (balkan11_medians) C++14
100 / 100
26 ms 2600 KB
#include <bits/stdc++.h>
using namespace std;
bool used[200005];
int inp[100000],n,li,hi;
void low_next() {
    while(used[li]) li++;
    printf("%d ",li),used[li]=true;
}
void high_next() {
    while(used[hi]) hi--;
    printf("%d ",hi),used[hi]=true;
}
int main() {
    scanf("%d",&n);
    li=1,hi=2*n-1;
    for(int i=0;i<n;i++) scanf("%d",&inp[i]);
    printf("%d ",inp[0]),used[inp[0]]=true;
    for(int i=1;i<n;i++) {
        if(inp[i-1]==inp[i]) low_next(),high_next();
        else if(inp[i-1]<inp[i]) {
            if(used[inp[i]]) high_next(),high_next();
            else {
                high_next();
                printf("%d ",inp[i]),used[inp[i]]=true;
            }
        } else {
            if(used[inp[i]]) low_next(),low_next();
            else {
                low_next();
                printf("%d ",inp[i]),used[inp[i]]=true;
            }
        }
    }
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:14:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
                   ^
medians.cpp:16:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=0;i<n;i++) scanf("%d",&inp[i]);
                                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2600 KB Output is correct
2 Correct 0 ms 2600 KB Output is correct
3 Correct 0 ms 2600 KB Output is correct
4 Correct 0 ms 2600 KB Output is correct
5 Correct 0 ms 2600 KB Output is correct
6 Correct 0 ms 2600 KB Output is correct
7 Correct 0 ms 2600 KB Output is correct
8 Correct 0 ms 2600 KB Output is correct
9 Correct 0 ms 2600 KB Output is correct
10 Correct 0 ms 2600 KB Output is correct
11 Correct 0 ms 2600 KB Output is correct
12 Correct 0 ms 2600 KB Output is correct
13 Correct 0 ms 2600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2600 KB Output is correct
2 Correct 0 ms 2600 KB Output is correct
3 Correct 3 ms 2600 KB Output is correct
4 Correct 9 ms 2600 KB Output is correct
5 Correct 9 ms 2600 KB Output is correct
6 Correct 19 ms 2600 KB Output is correct
7 Correct 26 ms 2600 KB Output is correct