# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
647694 | borgar02 | Zalmoxis (BOI18_zalmoxis) | C++17 | 511 ms | 75264 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
struct node {
node *ch[2];
bool marked, vis;
int h;
node(int h) : ch({NULL, NULL}), marked(false), vis(false), h(h) {}
node *go_to(int s) { if(ch[s] == NULL) { ch[!s] = new node(h - 1); return ch[s] = new node(h - 1); } return ch[s]; }
bool cansplit() { return !ch[0] && !ch[1] && h; }
};
node *root = new node(30);
bool add(int x, int curr = 30, node *t = root)
{
// cout << curr << "\n";
if(t -> vis) return false;
if(curr == x && !(t -> ch[0])) { return t -> vis = t -> marked = true;}
else if(curr == x) return false;
// cout << "Going left\n";
bool ok;
if(!(ok = add(x, curr - 1, t -> go_to(0)))) {
// cout << "Going right\n";
ok = add(x, curr - 1, t -> go_to(1));
}
if(!ok) t -> vis = true;
return ok;
}
const int N = 1e6 + 5;
int a[N];
int k;
int cnt;
void count_leaves(node *t = root)
{
if(t -> ch[0]) {
count_leaves(t -> ch[0]);
count_leaves(t -> ch[1]);
} else if(!t -> marked) cnt++;
}
void dfs(node *t = root)
{
if(!t -> ch[0] && !t -> marked && k && t -> cansplit()) {
k--;
t -> go_to(0);
}
if(t -> ch[0]) {
dfs(t -> ch[0]);
dfs(t -> ch[1]);
}
}
vector <int> res;
void dfs2(node *t = root)
{
if(t -> ch[0]) {
dfs2(t -> ch[0]);
dfs2(t -> ch[1]);
} else res.push_back(t -> h);
}
int main()
{
root -> go_to(0);
int n;
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> a[i];
assert(add(a[i]));
}
count_leaves();
k -= cnt;
dfs();
dfs2();
for(int x : res)
cout << x << " ";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |