Submission #545221

#TimeUsernameProblemLanguageResultExecution timeMemory
545221AbdelmagedNourPoklon (COCI17_poklon7)C++17
120 / 120
255 ms56048 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const int N=1000005; int n,L[N],R[N]; pair<int,int>res={0,0}; bool f(pair<int,int>a,pair<int,int>b){ if(a.first==0)return 0; if(b.first==0)return 1; if(a.first>b.first)return !f(b,a); while(a.first<b.first&&a.second){ a.first*=2; a.second--; } if(a.first>=b.first&&a.second>=b.second){ return 1; }else return 0; } void dfs(int v,int dep=0){ if(v<=0){ pair<int,int>val={-v,dep}; if(f(val,res))res=val; return; } dfs(L[v],dep+1); dfs(R[v],dep+1); } 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(res.first){ s+=char('0'+(res.first&1)); res.first/=2; } reverse(s.begin(),s.end()); cout<<s; for(int i=0;i<res.second;i++)cout<<0; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...