답안 #756505

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
756505 2023-06-11T18:25:18 Z sheldon Zalmoxis (BOI18_zalmoxis) C++14
95 / 100
132 ms 12220 KB
#include <bits/stdc++.h>

using namespace std;

void solve() {
    // ifstream cin ("zalmoxis.in");
    // ofstream cout ("zalmoxis.out");
    int n, k;
    cin >> n >> k;
    vector<int> st = {(int) 1e9};
    vector<int> a(n), ans;
    int done = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        assert(a[i] <= 1e9);
        if (a[i] == st.back()) {
            st.push_back(a[i]);
            while (st.size() > 1 && st.back() == st[st.size() - 2]) {
                st.pop_back();
                st.back()++;
            }
        } else if (a[i] > st.back()) {
            while (a[i] > st.back()) {
                ans.push_back(st.back());
                st.push_back(st.back());
                ++done;
                while (st.size() > 1 && st.back() == st[st.size() - 2]) {
                    st.pop_back();
                    st.back()++;
                }
            }
            st.push_back(a[i]);
            while (st.size() > 1 && st.back() == st[st.size() - 2]) {
                st.pop_back();
                st.back()++;
            }
        } else {
            st.push_back(a[i]);
        }
        ans.push_back(a[i]);
    }
    while (st.size() != 2) {
        ans.push_back(st.back());
        st.push_back(st.back());
        ++done;
        while (st.size() > 1 && st.back() == st[st.size() - 2]) {
            st.pop_back();
            st.back()++;
        }
    }
    while (st[1] < 30) {
        ++done;
        ans.push_back(st[1]);
        st[1]++;
    }
    while (done != k) {
        ++done;
        int x = ans.back();
        ans.pop_back();
        ans.push_back(x - 1);
        ans.push_back(x - 1);
    }
    for (int x : ans) cout << x << ' ';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 10544 KB Output is correct
2 Correct 128 ms 10304 KB Output is correct
3 Correct 128 ms 10352 KB Output is correct
4 Correct 128 ms 10304 KB Output is correct
5 Correct 127 ms 10300 KB Output is correct
6 Correct 127 ms 10344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 131 ms 10256 KB Output is correct
2 Correct 127 ms 10340 KB Output is correct
3 Incorrect 130 ms 10348 KB doesn't contain S as a subsequence
4 Correct 125 ms 10372 KB Output is correct
5 Correct 128 ms 10392 KB Output is correct
6 Correct 130 ms 10248 KB Output is correct
7 Correct 132 ms 10316 KB Output is correct
8 Correct 126 ms 10300 KB Output is correct
9 Correct 122 ms 9920 KB Output is correct
10 Correct 97 ms 10812 KB Output is correct
11 Correct 106 ms 10264 KB Output is correct
12 Correct 85 ms 12220 KB Output is correct
13 Correct 91 ms 12172 KB Output is correct
14 Correct 86 ms 12212 KB Output is correct