Submission #69968

#TimeUsernameProblemLanguageResultExecution timeMemory
69968vanogamZalmoxis (BOI18_zalmoxis)C++14
100 / 100
727 ms99548 KiB
#include<bits/stdc++.h>
using namespace std;
int a,s,d[1000002],f,g,h,j,k,l,i,n,m;
struct tre{
    int val;
    tre *L;
    tre *R;
    tre(){
        L=NULL;
        R=NULL;
        val=0;
    }
};
tre *root;
void bld(tre *&it,int lv){
    it=new tre();
    if(!it->L && !it->R && lv==d[a]) {it->val=1;a++;return;}
    if(lv>d[a]) bld(it->L,lv-1);
    if(a==n) {if(!it->R) h++;return;}
    if(it->L && lv>d[a]) return bld(it->R,lv-1);
    if(!it->R) h++;
}

void fnd(tre *&it,int lv){
    if(it->val) {cout<<lv<<" ";return;}
    if(!it->L) {
        if(h==k || lv==0) {cout<<lv<<" ";return;}
        h++;
        it->L=new tre();
        it->R=new tre();
    }
    fnd(it->L,lv-1);
    if(!it->R) it->R=new tre();
    fnd(it->R,lv-1);
}
main(){
    ios::sync_with_stdio(0);
    cin>>n>>k;
    for(i=0;i<n;i++){
        cin>>d[i];
    }

    bld(root,30);
    //cout<<h<<"*";
    fnd(root,30);
}

Compilation message (stderr)

zalmoxis.cpp:36:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...