#ifdef DEBUG
#include "debug.hpp"
#else
#pragma GCC optimize("Ofast")
#define trace(...)
#include <bits/stdc++.h>
#define endl '\n'
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
list<int> a;
int rem = 1 << 30;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
a.push_back(tmp);
rem -= 1 << tmp;
}
unsigned int st = 1 << 30;
for (auto it = a.begin(); it != a.end(); ++it) {
if (*it < __builtin_ctz(st)) {
st |= 1 << *it;
} else if (*it == __builtin_ctz(st)) {
st += 1 << *it;
} else {
int h = __builtin_ctz(st);
rem -= 1 << h;
it = a.insert(it, h);
st += 1 << h;
}
}
list<int> b;
while (__builtin_ctz(st) < 30) {
int h = __builtin_ctz(st);
rem -= 1 << h;
b.push_back(h);
trace(h);
st += 1 << h;
}
assert(rem >= 0);
for (; rem; rem -= rem & -rem) {
b.push_back(__builtin_ctz(rem));
}
int left = (n + k) - (a.size() + b.size());
assert(left >= 0);
auto it = b.begin();
for (int i = 0; i < left; ++i) {
while (*it == 0)
++it;
--(*it);
it = b.insert(it, *it);
}
a.splice(a.end(), b);
copy(a.begin(), a.end(), ostream_iterator<int>(cout, " "));
cout << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
33784 KB |
Output is correct |
2 |
Correct |
221 ms |
33900 KB |
Output is correct |
3 |
Correct |
216 ms |
33784 KB |
Output is correct |
4 |
Correct |
216 ms |
33864 KB |
Output is correct |
5 |
Correct |
217 ms |
33784 KB |
Output is correct |
6 |
Correct |
214 ms |
33656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
33796 KB |
Output is correct |
2 |
Correct |
225 ms |
33752 KB |
Output is correct |
3 |
Execution timed out |
1074 ms |
31608 KB |
Time limit exceeded |
4 |
Correct |
219 ms |
33756 KB |
Output is correct |
5 |
Correct |
241 ms |
33764 KB |
Output is correct |
6 |
Correct |
228 ms |
33784 KB |
Output is correct |
7 |
Correct |
225 ms |
33856 KB |
Output is correct |
8 |
Correct |
226 ms |
33784 KB |
Output is correct |
9 |
Correct |
205 ms |
33812 KB |
Output is correct |
10 |
Correct |
175 ms |
33688 KB |
Output is correct |
11 |
Correct |
187 ms |
33656 KB |
Output is correct |
12 |
Correct |
153 ms |
33656 KB |
Output is correct |
13 |
Correct |
152 ms |
33744 KB |
Output is correct |
14 |
Correct |
148 ms |
33796 KB |
Output is correct |