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