이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
zalmoxis.cpp:36:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |