#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k, arr[N];
vector<int> nums[N];
vector<pair<int, int>> v, vnext;
vector<int> vec, ans;
bool isneeded[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 cur = 1; cur <= 29; cur++){
reverse(v.begin(), v.end());
while(!v.empty()){
pair<int, int> p = v.back(); v.pop_back();
if(p.first != cur) vnext.push_back(p);
else{
if(!v.empty() && v.back().first == cur){
vnext.push_back({cur + 1, v.back().second});
v.pop_back();
}
else{
nums[p.second].push_back(cur);
vnext.push_back({cur + 1, p.second});
}
}
}
swap(v, vnext);
vnext.clear();
}
for(int i = 0; i < n; i++){
for(auto x : nums[i]) vec.push_back(x);
}
int ptr = 0;
for(int i = 0; i < vec.size(); i++){
if(ptr < n && vec[ptr] == arr[i]) isneeded[i] = true, ptr++;
}
for(int i = 0; i < vec.size(); i++){
if(isneeded[i]) ans.push_back(vec[i]);
else{
stack<int> stk;
stk.push(vec[i]);
while(!stk.empty() && ans.size() + (vec.size() - i - 1) + stk.size() < n + k){
int cur = stk.top(); stk.pop();
if(cur == 1) ans.push_back(1);
else stk.push(cur - 1), stk.push(cur - 1);
}
while(!stk.empty()){
ans.push_back(stk.top());
stk.pop();
}
}
}
for(auto x : ans) cout << x << " ";
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | for(int i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
zalmoxis.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int i = 0; i < vec.size(); i++){
| ~~^~~~~~~~~~~~
zalmoxis.cpp:70:73: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
70 | while(!stk.empty() && ans.size() + (vec.size() - i - 1) + stk.size() < n + k){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
376 ms |
183936 KB |
Execution killed with signal 11 |
2 |
Runtime error |
363 ms |
180012 KB |
Execution killed with signal 11 |
3 |
Runtime error |
344 ms |
182308 KB |
Execution killed with signal 11 |
4 |
Runtime error |
402 ms |
181636 KB |
Execution killed with signal 11 |
5 |
Runtime error |
338 ms |
181064 KB |
Execution killed with signal 11 |
6 |
Runtime error |
393 ms |
186968 KB |
Execution killed with signal 11 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
367 ms |
183000 KB |
Execution killed with signal 11 |
2 |
Runtime error |
373 ms |
186124 KB |
Execution killed with signal 11 |
3 |
Runtime error |
369 ms |
179972 KB |
Execution killed with signal 11 |
4 |
Runtime error |
338 ms |
180344 KB |
Execution killed with signal 11 |
5 |
Runtime error |
347 ms |
181328 KB |
Execution killed with signal 11 |
6 |
Runtime error |
363 ms |
183568 KB |
Execution killed with signal 11 |
7 |
Runtime error |
352 ms |
180904 KB |
Execution killed with signal 11 |
8 |
Runtime error |
331 ms |
178572 KB |
Execution killed with signal 11 |
9 |
Runtime error |
328 ms |
158680 KB |
Execution killed with signal 11 |
10 |
Incorrect |
211 ms |
52180 KB |
doesn't contain S as a subsequence |
11 |
Runtime error |
244 ms |
121972 KB |
Execution killed with signal 11 |
12 |
Incorrect |
88 ms |
29768 KB |
doesn't contain S as a subsequence |
13 |
Incorrect |
99 ms |
29788 KB |
doesn't contain S as a subsequence |
14 |
Correct |
87 ms |
29800 KB |
Output is correct |