# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
545218 | AbdelmagedNour | Poklon (COCI17_poklon7) | C++17 | 293 ms | 81348 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 <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N=1000005;
int n,L[N],R[N];
pair<int,int>val[N];
pair<int,int>Max(pair<int,int>a,pair<int,int>b){
if(a.first==0)return b;
if(b.first==0)return a;
while(a.first<b.first&&a.second){
a.first*=2;
a.second--;
}
if(a.first>=b.first&&a.second>=b.second){
while((a.first&1)==0){
a.first>>=1;
a.second++;
}
return a;
}else return b;
}
void dfs(int v){
pair<int,int>l={0,0},r={0,0};
if(L[v]>0){
dfs(L[v]);
l=val[L[v]];
}else l={-L[v],0};
if(R[v]>0){
dfs(R[v]);
r=val[R[v]];
}else r={-R[v],0};
val[v]=Max(l,r);
val[v].second++;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>L[i]>>R[i];
dfs(1);
string s="";
while(val[1].first){
s+=char('0'+(val[1].first&1));
val[1].first/=2;
}
reverse(s.begin(),s.end());
cout<<s;
for(int i=0;i<val[1].second;i++)cout<<0;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |