답안 #24801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24801 2017-06-14T04:42:16 Z rondojim 중앙값 배열 (balkan11_medians) C++14
100 / 100
39 ms 3460 KB
#include <stdio.h>

const int MAXN = 2e5 + 5;

int vis[MAXN], minimum, maximum, A[MAXN], B[MAXN], N;

void plus(){ while(vis[minimum]) minimum++; }
void minus(){ while(vis[maximum]) maximum--; }

int main(){
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif
  scanf("%d", &N);
  for(int i=1; i<=N; ++i) scanf("%d", &B[i]);
  minimum = 0, maximum = 2 * N;
  vis[minimum] = vis[maximum] = vis[B[1]] = 1, A[1] = B[1];
  for(int i=2; i<=N; ++i){
    if(B[i - 1] == B[i]){
      plus(); A[2 * i - 2] = minimum, vis[minimum] = 1;
      minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
    }
    else if(B[i - 1] < B[i]){
      if(!vis[B[i]]){
        A[2 * i - 2] = B[i], vis[B[i]] = 1;
        minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
      }
      else{
        minus(); A[2 * i - 2] = maximum, vis[maximum] = 1;
        minus(); A[2 * i - 1] = maximum, vis[maximum] = 1;
      }
    }
    else if(B[i - 1] > B[i]){
      if(!vis[B[i]]){
        A[2 * i - 2] = B[i], vis[B[i]] = 1;
        plus(); A[2 * i - 1] = minimum, vis[minimum] = 1;
      }
      else{
        plus(); A[2 * i - 2] = minimum, vis[minimum] = 1;
        plus(); A[2 * i - 1] = minimum, vis[minimum] = 1;
      }
    }
  }
  for(int i=1; i<2*N; ++i) printf("%d ", A[i]);
  puts("");
  return 0;
}

Compilation message

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