이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <chrono>
#include <random>
#include <cassert>
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
const int ms = 1001000;
int n, k, cur = 0;
int a[ms];
bool got = false;
int lookahead() { return cur < n ? a[cur] : -1; }
void print(int x) {
if(got) std::cout << ' ';
got = true;
std::cout << x;
}
int rest = 1 << 30;
void solve(int N) {
assert(N >= 0);
if(lookahead() == N) {
print(N);
cur++;
} else if(k > 0 && rest - (1 << N) >= k - 1) {
print(N);
rest -= 1 << N;
k--;
} else {
solve(N-1);
solve(N-1);
}
}
int main() {
std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
std::cin >> n >> k;
for(int i = 0; i < n; i++) {
std::cin >> a[i];
rest -= 1 << a[i];
}
solve(30);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |