답안 #29205

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
29205 2017-07-18T16:15:47 Z Nirjhor 중앙값 배열 (balkan11_medians) C++14
100 / 100
33 ms 3604 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 200010;

bitset <N> vis;
int n, a[N], b[N], l, r;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", b + i);
  }
  a[1] = b[1];
  l = 0, r = n + n;
  vis[b[1]] = vis[l] = vis[r] = 1;
  for (int i = 2, j = 2; i <= n; ++i, j += 2) {
    if (b[i] == b[i - 1]) {
      while (vis[l]) ++l;
      while (vis[r]) --r;
      a[j] = l, a[j + 1] = r;
      vis[l] = vis[r] = 1;
    }
    if (b[i] < b[i - 1]) {
      if (vis[b[i]]) {
        while (vis[l]) ++l;
        a[j] = l, vis[l] = 1;
        while (vis[l]) ++l;
        a[j + 1] = l, vis[l] = 1;
      } else {
        a[j] = b[i], vis[b[i]] = 1;
        while (vis[l]) ++l;
        a[j + 1] = l, vis[l] = 1;
      }
    }
    if (b[i] > b[i - 1]) {
      if (vis[b[i]]) {
        while (vis[r]) --r;
        a[j] = r, vis[r] = 1;
        while (vis[r]) --r;
        a[j + 1] = r, vis[r] = 1;
      } else {
        a[j] = b[i], vis[b[i]] = 1;
        while (vis[r]) --r;
        a[j + 1] = r, vis[r] = 1;
      }
    }
  }
  for (int i = 1; i < n + n; ++i) {
    printf("%d ", a[i]);
  }
  puts("");
  return 0;
}

Compilation message

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