답안 #656851

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656851 2022-11-08T10:48:33 Z MilosMilutinovic Zalmoxis (BOI18_zalmoxis) C++14
45 / 100
166 ms 59176 KB
#include <bits/stdc++.h>

using namespace std;

void Push(vector<int>& v) {
  while (v.size() >= 2) {
    int sz = (int) v.size();
    if (v[sz - 1] == v[sz - 2]) {
      int x = v[sz - 1];
      v.pop_back();
      v.pop_back();
      v.push_back(x + 1);
    } else {
      break;
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  a.push_back(30);
  n++;
  vector<int> stk;
  vector<pair<int, int>> ans;
  for (int i = 0; i < n; i++) {
    while (!stk.empty() && stk.back() < a[i]) {
      int x = stk.back();
      ans.emplace_back(stk.back(), 1);
      stk.push_back(stk.back());
      Push(stk);
    }
    ans.emplace_back(a[i], 0);
    stk.push_back(a[i]);
    Push(stk);
  }
  ans.pop_back();
  for (auto& p : ans) {
    k -= p.second;
  }
  vector<int> res;
  function<void(int)> Add = [&](int x) {
    if (x == 1 || k == 0) {
      res.push_back(x);
    } else {
      k--;
      Add(x - 1);
      Add(x - 1);
    }
  };
  for (auto& p : ans) {
    if (p.second == 0) {
      Add(p.first);
    } else {
      res.push_back(p.first);
    }
  }
  for (auto& p : res) {
    cout << p << " ";
  }
  return 0;
}

Compilation message

zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:34:11: warning: unused variable 'x' [-Wunused-variable]
   34 |       int x = stk.back();
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Correct 151 ms 24220 KB Output is correct
2 Correct 166 ms 24204 KB Output is correct
3 Correct 143 ms 24292 KB Output is correct
4 Correct 164 ms 24240 KB Output is correct
5 Correct 148 ms 24136 KB Output is correct
6 Correct 166 ms 24184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 147 ms 24128 KB doesn't contain S as a subsequence
2 Correct 141 ms 24208 KB Output is correct
3 Incorrect 146 ms 24136 KB doesn't contain S as a subsequence
4 Correct 158 ms 24236 KB Output is correct
5 Incorrect 143 ms 24252 KB doesn't contain S as a subsequence
6 Incorrect 147 ms 24220 KB doesn't contain S as a subsequence
7 Incorrect 155 ms 24184 KB doesn't contain S as a subsequence
8 Incorrect 143 ms 24280 KB doesn't contain S as a subsequence
9 Incorrect 133 ms 22520 KB doesn't contain S as a subsequence
10 Incorrect 117 ms 32052 KB doesn't contain S as a subsequence
11 Incorrect 116 ms 18504 KB doesn't contain S as a subsequence
12 Incorrect 108 ms 59176 KB doesn't contain S as a subsequence
13 Correct 129 ms 59148 KB Output is correct
14 Incorrect 1 ms 316 KB Unexpected end of file - int32 expected