# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
335452 | 2020-12-12T16:58:14 Z | 3funnn | Zalmoxis (BOI18_zalmoxis) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #define mp make_pair using namespace std; const int NMAX = 1000000; int need; void dfs(int val){ if (need == 0 || val == 0){ fout << val << " "; return; } --need; dfs(val - 1); dfs(val - 1); } int stk[NMAX + 5], top; void Compress(){ while (top >= 2 && stk[top] == stk[top - 1]){ --top; ++stk[top]; } } int main() { int N, K; cin >> N >> K; vector <int> v(N); for (int i = 0;i < N;++i) cin >> v[i]; need = K; vector <pair <int, bool>> a; stk[++top] = 31; for (int i = 0;i < N;++i){ while (v[i] > stk[top]){ --need; a.push_back(mp(stk[top], true)); ++stk[top]; Compress(); } a.push_back(mp(v[i], false)); stk[++top] = v[i]; Compress(); } while (stk[2] != 30){ --need; a.push_back(mp(stk[top], true)); ++stk[top]; Compress(); } for (int i = 0;i < a.size();++i){ if (a[i].second == 0) cout << a[i].first << " "; else dfs(a[i].first); } return 0; }