#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k, arr[N], lftcnt;
vector<pair<int, int>> v, v2;
vector<int> nums[N], vec, ans;
bool req[N];
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> arr[i];
nums[i].push_back(arr[i]);
v.push_back({arr[i], i});
}
for(int num = 1; num <= 29; num++){
v2 = v;
v.clear();
for(auto p : v2){
if(v.empty()) v.push_back(p);
else{
if(v.back().first == num){
if(p.first == num){
v.back().first = num + 1;
v.back().second = p.second;
}
else{
v.back().first = num + 1;
nums[v.back().second].push_back(num);
v.push_back(p);
}
}
else v.push_back(p);
}
}
if(v.back().first == num){
v.back().first = num + 1;
nums[v.back().second].push_back(num);
}
}
for(int i = 0; i < n; i++){
for(auto j : nums[i]){
vec.push_back(j);
}
}
int ptr = 0;
for(int i = 0; i < vec.size(); i++){
if(ptr < n && vec[i] == arr[ptr]) req[i] = true, ptr++;
}
lftcnt = (n + k) - vec.size();
for(int i = 0; i < vec.size(); i++){
if(!req[i] && lftcnt){
int lftlog = __lg(lftcnt + 1);
if(vec[i] - lftlog <= 1){
for(int j = 0; j < (1 << (vec[i] - 1)); j++) ans.push_back(1);
lftcnt -= (1 << (vec[i] - 1)) - 1;
}
else{
vector<int> tmp;
for(int j = 0; j < (1 << lftlog); j++) tmp.push_back(vec[i] - lftlog);
lftcnt -= (1 << lftlog) - 1;
while(lftcnt > 0){
ans.push_back(tmp.back() - 1);
ans.push_back(tmp.back() - 1);
lftcnt--;
tmp.pop_back();
}
for(auto j : tmp) ans.push_back(j);
}
}
else ans.push_back(vec[i]);
}
for(auto i : ans) cout << i << " ";
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:64:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
zalmoxis.cpp:70:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
387 ms |
184672 KB |
Execution killed with signal 11 |
2 |
Runtime error |
357 ms |
180252 KB |
Execution killed with signal 11 |
3 |
Runtime error |
376 ms |
182668 KB |
Execution killed with signal 11 |
4 |
Runtime error |
358 ms |
182064 KB |
Execution killed with signal 6 |
5 |
Runtime error |
411 ms |
181436 KB |
Execution killed with signal 6 |
6 |
Runtime error |
407 ms |
187360 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
391 ms |
183564 KB |
Execution killed with signal 11 |
2 |
Runtime error |
388 ms |
186428 KB |
Execution killed with signal 11 |
3 |
Runtime error |
352 ms |
180400 KB |
Execution killed with signal 11 |
4 |
Runtime error |
359 ms |
180464 KB |
Execution killed with signal 6 |
5 |
Runtime error |
346 ms |
181780 KB |
Execution killed with signal 11 |
6 |
Runtime error |
371 ms |
183688 KB |
Execution killed with signal 11 |
7 |
Runtime error |
363 ms |
181308 KB |
Execution killed with signal 11 |
8 |
Runtime error |
330 ms |
179032 KB |
Execution killed with signal 11 |
9 |
Runtime error |
342 ms |
159464 KB |
Execution killed with signal 11 |
10 |
Incorrect |
184 ms |
52436 KB |
not a zalsequence |
11 |
Runtime error |
249 ms |
123424 KB |
Execution killed with signal 11 |
12 |
Incorrect |
77 ms |
31716 KB |
not a zalsequence |
13 |
Incorrect |
80 ms |
31676 KB |
not a zalsequence |
14 |
Correct |
79 ms |
31764 KB |
Output is correct |