Submission #656476

# Submission time Handle Problem Language Result Execution time Memory
656476 2022-11-07T15:07:18 Z MilosMilutinovic Zalmoxis (BOI18_zalmoxis) C++14
35 / 100
157 ms 22344 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;
  auto Add = [&](int x) {
    vector<int> t(1, x);
    vector<int> f;
    while (!t.empty() && k > 0) {
      int x = t.back();
      if (x > 1) {
        t.push_back(x - 1);
        t.push_back(x - 1);
        t.pop_back();
        k--;
      } else {
        res.push_back(1);
        t.pop_back();
      }
    }
    while (!t.empty()) {
      res.push_back(t.back());
      t.pop_back();
    }
  };
  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();
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 148 ms 22268 KB Output is correct
2 Correct 155 ms 22280 KB Output is correct
3 Correct 148 ms 22240 KB Output is correct
4 Correct 152 ms 22280 KB Output is correct
5 Correct 149 ms 22276 KB Output is correct
6 Correct 154 ms 22256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 149 ms 22236 KB not a zalsequence
2 Correct 153 ms 22276 KB Output is correct
3 Incorrect 151 ms 22268 KB not a zalsequence
4 Incorrect 152 ms 22260 KB not a zalsequence
5 Incorrect 151 ms 22268 KB not a zalsequence
6 Incorrect 149 ms 22344 KB not a zalsequence
7 Incorrect 157 ms 22252 KB not a zalsequence
8 Incorrect 153 ms 22272 KB not a zalsequence
9 Incorrect 142 ms 20896 KB not a zalsequence
10 Incorrect 99 ms 11084 KB not a zalsequence
11 Incorrect 118 ms 17556 KB not a zalsequence
12 Incorrect 71 ms 6348 KB not a zalsequence
13 Incorrect 72 ms 6304 KB not a zalsequence
14 Incorrect 76 ms 6340 KB not a zalsequence