답안 #865641

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865641 2023-10-24T12:54:23 Z Blagoj Zalmoxis (BOI18_zalmoxis) C++17
100 / 100
116 ms 59584 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    v.push_back(30);
    n++;
    vector<int> stk;
    vector<pair<int, int>> ans;
    for (int i = 0; i < n; i++) {
        while (stk.size() && stk.back() < v[i]) {
            int val = stk.back();
            ans.push_back({val, 1});
            stk.push_back(val);
            CPS(stk);
        }
        stk.push_back(v[i]);
        ans.push_back({v[i], 0});
        CPS(stk);
    }
    ans.pop_back();
    for (auto x : ans) k -= x.second;
    vector<int> res;
    function<void(int)> Add = [&] (int x) {
        if (k == 0 || x == 1) res.push_back(x);
        else {
            k--;
            Add(x - 1);
            Add(x - 1);
        }
    };
    for (auto x : ans) {
        if (x.second == 1) {
            Add(x.first);
        }
        else res.push_back(x.first);
    }
    for (auto x : res) cout << x << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 25348 KB Output is correct
2 Correct 107 ms 26552 KB Output is correct
3 Correct 103 ms 24836 KB Output is correct
4 Correct 106 ms 24840 KB Output is correct
5 Correct 105 ms 24840 KB Output is correct
6 Correct 108 ms 24512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 110 ms 25604 KB Output is correct
2 Correct 107 ms 25356 KB Output is correct
3 Correct 106 ms 26128 KB Output is correct
4 Correct 114 ms 26424 KB Output is correct
5 Correct 109 ms 25860 KB Output is correct
6 Correct 116 ms 24620 KB Output is correct
7 Correct 107 ms 25964 KB Output is correct
8 Correct 106 ms 25256 KB Output is correct
9 Correct 101 ms 23204 KB Output is correct
10 Correct 94 ms 37932 KB Output is correct
11 Correct 88 ms 20380 KB Output is correct
12 Correct 97 ms 59332 KB Output is correct
13 Correct 103 ms 59584 KB Output is correct
14 Correct 55 ms 6440 KB Output is correct