제출 #658032

#제출 시각아이디문제언어결과실행 시간메모리
658032stevancvZalmoxis (BOI18_zalmoxis)C++14
65 / 100
170 ms16364 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 3e3 + 2; const int inf = 2e9; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; vector<int> a(n + 1); a[n] = 30; stack<int> s; vector<pair<int, int>> ans; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i <= n; i++) { if (i == 0) { ans.push_back({a[i], 0}); s.push(a[i]); continue; } while (s.top() < a[i]) { int x = s.top(); ans.push_back({x, 1}); k--; s.push(x); while (s.size() > 1) { x = s.top(); s.pop(); if (x == s.top()) s.top()++; else {s.push(x); break;} } } int x = a[i]; ans.push_back({a[i], 0}); s.push(a[i]); while (s.size() > 1) { x = s.top(); s.pop(); if (x == s.top()) s.top()++; else {s.push(x); break;} } } function<void(int)> F = [&] (int x) { int y = min((int)pow(2, x - 1) - 1, k); k -= y; int u = log2(y + 1); int dif = y - pow(2, u) + 1; for (int i = 1; i <= y + 1; i++) { if (dif > 0) { cout << x - u - 1 << sp << x - u - 1 << sp; i += 1; dif -= 1; } else cout << x - u << sp; } }; for (auto u : ans) { if (u.first == 30) break; if (u.second == 0) cout << u.first << sp; else F(u.first); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...