이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |