제출 #756502

#제출 시각아이디문제언어결과실행 시간메모리
756502sheldonZalmoxis (BOI18_zalmoxis)C++14
35 / 100
184 ms11192 KiB
#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()++;
        }
    }
    
    assert(st[1] <= 30);
    for (int it = st[1]; it < st[1] + k - done; ++it) {
        ans.push_back(it);
    }
    st.clear();
    for (int i = 0; i < ans.size(); ++i) {
        st.push_back(ans[i]);
        while (st.size() > 1 && st.back() == st[st.size() - 2]) {
            st.pop_back();
            st.back()++;
        }
    }
    for (int x : ans) cout << x << ' ';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
}

컴파일 시 표준 에러 (stderr) 메시지

zalmoxis.cpp: In function 'void solve()':
zalmoxis.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 0; i < ans.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...