#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <chrono>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <queue>
#include <bitset>
#include <cmath>
typedef long long ll;
typedef long double ld;
using namespace std;
void compress(vector<int>& st)
{
while (st.size() >= 2 && st[st.size() - 2] == st[st.size() - 1])
{
int x = st.back();
st.pop_back();
st.pop_back();
st.push_back(x + 1);
}
}
void split(int x, int k, vector<int>& v)
{
if (k == 1)
{
v.push_back(x);
return;
}
int l = min(k - 1, 1 << (x - 2));
split(x - 1, l, v);
split(x - 1, k - l, v);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
vector<int> st, ans1, added;
for (int i = 0; i < n; i++)
{
while (!st.empty() && st.back() < v[i])
{
st.push_back(st.back());
ans1.push_back(st.back());
added.push_back(1);
compress(st);
}
st.push_back(v[i]);
ans1.push_back(v[i]);
added.push_back(0);
compress(st);
}
while (st.size() > 1 || st.back() < 30)
{
st.push_back(st.back());
ans1.push_back(st.back());
added.push_back(1);
compress(st);
}
k = n + k - ans1.size();
vector<int> ans2;
for (int i = 0; i < ans1.size(); i++)
{
if (added[i])
{
split(ans1[i], min(k + 1, 1 << ans1[i]), ans2);
}
else
{
ans2.push_back(ans1[i]);
}
}
for (int i = 0; i < ans2.size(); i++)
{
cout << ans2[i] << " \n"[i == ans2.size() - 1];
}
return 0;
}
Compilation message
zalmoxis.cpp: In function 'int main()':
zalmoxis.cpp:71:23: 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 < ans1.size(); i++)
| ~~^~~~~~~~~~~~~
zalmoxis.cpp:82:23: 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 < ans2.size(); i++)
| ~~^~~~~~~~~~~~~
zalmoxis.cpp:84:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | cout << ans2[i] << " \n"[i == ans2.size() - 1];
| ~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
20240 KB |
Output is correct |
2 |
Correct |
149 ms |
20260 KB |
Output is correct |
3 |
Correct |
177 ms |
20260 KB |
Output is correct |
4 |
Correct |
142 ms |
20248 KB |
Output is correct |
5 |
Correct |
149 ms |
20224 KB |
Output is correct |
6 |
Correct |
163 ms |
20416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
141 ms |
20208 KB |
Expected EOF |
2 |
Correct |
148 ms |
20176 KB |
Output is correct |
3 |
Runtime error |
426 ms |
262148 KB |
Execution killed with signal 9 |
4 |
Incorrect |
164 ms |
20260 KB |
Expected EOF |
5 |
Incorrect |
163 ms |
20292 KB |
Expected EOF |
6 |
Incorrect |
146 ms |
20248 KB |
Expected EOF |
7 |
Incorrect |
146 ms |
20180 KB |
Expected EOF |
8 |
Runtime error |
412 ms |
262148 KB |
Execution killed with signal 9 |
9 |
Runtime error |
450 ms |
262148 KB |
Execution killed with signal 9 |
10 |
Runtime error |
386 ms |
262148 KB |
Execution killed with signal 9 |
11 |
Runtime error |
399 ms |
262148 KB |
Execution killed with signal 9 |
12 |
Runtime error |
392 ms |
262148 KB |
Execution killed with signal 9 |
13 |
Runtime error |
383 ms |
262148 KB |
Execution killed with signal 9 |
14 |
Runtime error |
421 ms |
262148 KB |
Execution killed with signal 9 |