# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
66388 | KLPP | Poklon (COCI17_poklon7) | C++14 | 412 ms | 136880 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdio.h>
#include<stack>
using namespace std;
typedef long long int lld;
typedef pair<lld,int> Z;
lld scales[10000000][2];
Z maximo(Z x,Z y){
if(x.second<y.second)return maximo(y,x);
Z a,b;
a=x;
b=y;
a.second-=b.second;
if(a.second>32){
return x;
}
for(int i=0;i<a.second;i++){
a.first*=2;
}
if(a.first>b.first)return x;
return y;
}
pair<lld,int> ans(int x){
Z r1;
if(scales[x][0]>0){
r1=ans(scales[x][0]);
}else r1=pair<lld,int>(-scales[x][0],0);
Z r2;
if(scales[x][1]>0){
r2=ans(scales[x][1]);
}else r2=pair<lld,int>(-scales[x][1],0);
Z R=maximo(r1,r2);
R.second++;
return R;
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%lld %lld",&scales[i+1][0],&scales[i+1][1]);
}
Z R=ans(1);
stack<int> b1;
while(R.first>0){
b1.push(R.first%2);
R.first/=2;
}
while(!b1.empty()){
cout<<b1.top();b1.pop();
}
for(int i=0;i<R.second;i++)cout<<"0";
cout<<endl;
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |