#include <bits/stdc++.h>
using namespace std;
#define ll long long
// #define int long long
#define endl '\n'
#define all(x) x.begin(),x.end()
const ll MOD = 1e9 + 7, SZ = 1e5 + 10, INF = 1e18;
int n, k, sz;
void solve(int x){
if(sz == n + k || x == 0){
cout << x << ' ';
return;
}
sz++;
solve(x - 1);
solve(x - 1);
}
vector<int> vec, s, ans;
int32_t main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
int arr[n];
for(int &i : arr)
cin >> i;
//--//
int idx = 1;
s.push_back(arr[0]);
ans.push_back(arr[0]);
while(s.back() != 30){
// cout << s.back() << endl;
if(idx == n){
ans.push_back(s.back());
vec.push_back(ans.size() - 1);
s.push_back(s.back());
while(s.size() > 1 && (s[s.size() - 1] == s[s.size() - 2] || s[s.size() - 1] < 0)){
// cout << idx << ' ' << s[s.size() - 1] << ' ' << s[s.size() - 2] << endl;
s.pop_back();
s.back()++;
}
continue;
}
if(arr[idx] > s.back()){
ans.push_back(s.back());
vec.push_back(ans.size() - 1);
s.push_back(s.back());
}
else{
ans.push_back(arr[idx]);
s.push_back(arr[idx]);
idx++;
}
while(s.size() > 1 && (s[s.size() - 1] == s[s.size() - 2] || s[s.size() - 1] < 0)){
// cout << idx << ' ' << s[s.size() - 1] << ' ' << s[s.size() - 2] << endl;
s.pop_back();
s.back()++;
}
}
reverse(all(vec));
sz = ans.size();
for(int i=0;i<ans.size();i++){
if(vec.back() == i)
solve(ans[i]);
else
cout << ans[i] << ' ';
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int32_t main()':
zalmoxis.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<ans.size();i++){
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
135 ms |
10296 KB |
Output is correct |
2 |
Correct |
141 ms |
10356 KB |
Output is correct |
3 |
Correct |
159 ms |
10252 KB |
Output is correct |
4 |
Correct |
138 ms |
10348 KB |
Output is correct |
5 |
Correct |
135 ms |
10344 KB |
Output is correct |
6 |
Correct |
135 ms |
10288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
153 ms |
10368 KB |
Output is correct |
2 |
Correct |
136 ms |
10328 KB |
Output is correct |
3 |
Incorrect |
154 ms |
10340 KB |
Unexpected end of file - int32 expected |
4 |
Correct |
135 ms |
10332 KB |
Output is correct |
5 |
Correct |
133 ms |
10352 KB |
Output is correct |
6 |
Correct |
142 ms |
10336 KB |
Output is correct |
7 |
Correct |
142 ms |
10336 KB |
Output is correct |
8 |
Correct |
136 ms |
10332 KB |
Output is correct |
9 |
Incorrect |
131 ms |
10676 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
56 ms |
5564 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
89 ms |
7860 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
0 ms |
212 KB |
Unexpected end of file - int32 expected |