#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 5;
int n, k, arr[N], onecnt[N], needcnt;
struct Item{
int x;
vector<int> nums;
};
vector<Item> a, b;
vector<int> newnums[N];
vector<int> v, ans;
bool caninc[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];
a.push_back({arr[i], {arr[i]}});
}
for(int num = 1; num <= 29; num++){
swap(a, b);
a.clear();
while(!b.empty()){
if(b[b.size() - 1].x == num){
if(b.size() >= 2 && b[b.size() - 2].x == num){
vector<int> tmp;
for(auto i : b[b.size() - 2].nums) tmp.push_back(i);
for(auto i : b[b.size() - 1].nums) tmp.push_back(i);
a.push_back({num + 1, tmp});
b.pop_back(), b.pop_back();
}
else{
vector<int> tmp;
tmp.push_back(num);
for(auto i : b[b.size() - 1].nums) tmp.push_back(i);
a.push_back({num + 1, tmp});
b.pop_back();
}
}
else{
a.push_back({b[b.size() - 1].x, b[b.size() - 1].nums});
b.pop_back();
}
}
reverse(a.begin(), a.end());
}
v = a[0].nums;
for(int i = 0; i < v.size(); i++) newnums[i].push_back(v[i]);
needcnt = (n + k) - v.size();
int ptr = 0;
for(int i = 0; i < v.size(); i++){
if(ptr < n && v[i] == arr[i]) ptr++;
else caninc[i] = true;
}
for(int i = 0; i < v.size(); i++){
if(caninc[i]){
while(needcnt > 0 && !newnums[i].empty()){
if(newnums[i].back() == 1){
onecnt[i]++;
newnums[i].pop_back();
}
else{
int x = newnums[i].back();
newnums[i].pop_back();
needcnt--;
newnums[i].push_back(x - 1);
newnums[i].push_back(x - 1);
}
}
}
}
for(int i = 0; i < v.size(); i++){
for(int j = 0; j < onecnt[i]; j++) ans.push_back(1);
for(auto j : newnums[i]) ans.push_back(j);
}
for(auto i : ans) cout << i << " ";
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 0; i < v.size(); i++) newnums[i].push_back(v[i]);
| ~~^~~~~~~~~~
zalmoxis.cpp:77:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
zalmoxis.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
zalmoxis.cpp:103:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
103 | for(int i = 0; i < v.size(); i++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1095 ms |
163056 KB |
Time limit exceeded |
2 |
Execution timed out |
1060 ms |
163080 KB |
Time limit exceeded |
3 |
Execution timed out |
1095 ms |
163056 KB |
Time limit exceeded |
4 |
Execution timed out |
1093 ms |
163072 KB |
Time limit exceeded |
5 |
Execution timed out |
1103 ms |
163136 KB |
Time limit exceeded |
6 |
Execution timed out |
1086 ms |
162996 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1097 ms |
163008 KB |
Time limit exceeded |
2 |
Execution timed out |
1082 ms |
163124 KB |
Time limit exceeded |
3 |
Execution timed out |
1097 ms |
162888 KB |
Time limit exceeded |
4 |
Execution timed out |
1104 ms |
163024 KB |
Time limit exceeded |
5 |
Execution timed out |
1096 ms |
163060 KB |
Time limit exceeded |
6 |
Execution timed out |
1098 ms |
163028 KB |
Time limit exceeded |
7 |
Execution timed out |
1099 ms |
163096 KB |
Time limit exceeded |
8 |
Execution timed out |
1075 ms |
163056 KB |
Time limit exceeded |
9 |
Execution timed out |
1083 ms |
149788 KB |
Time limit exceeded |
10 |
Incorrect |
484 ms |
91824 KB |
doesn't contain S as a subsequence |
11 |
Incorrect |
728 ms |
105920 KB |
doesn't contain S as a subsequence |
12 |
Incorrect |
110 ms |
53244 KB |
doesn't contain S as a subsequence |
13 |
Incorrect |
26 ms |
47192 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
105 ms |
53300 KB |
not a zalsequence |