Submission #375941

#TimeUsernameProblemLanguageResultExecution timeMemory
375941EndRayZalmoxis (BOI18_zalmoxis)C++17
100 / 100
187 ms39664 KiB
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

int n, k;
vector<pair<int, int>> ans;
vector<int> s;

void push(int x){
    if(s.empty())
        s.push_back(x);
    else if(s.back() == x){
        s.pop_back();
        push(x+1);
    }
    else s.push_back(x);
}

void combine(){
    ans.emplace_back(s.back(), 1);
    --k;
    push(s.back());
}

void try_push(int x){
    while(!s.empty() && s.back() < x)
        combine();
    ans.emplace_back(x, 0);
    push(x);
}

void print(pair<int, int> p){
    if(!p.y || !k || p.x == 1){
        cout << p.x << " ";
        return;
    }
    --k;
    print({p.x-1, 1});
    print({p.x-1, 1});
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        try_push(x);
    }
    while(s.back() < 30)
        combine();
    for(auto el : ans)
        print(el);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...