Submission #315400

#TimeUsernameProblemLanguageResultExecution timeMemory
315400Ahmad_HasanPoklon (COCI17_poklon7)C++17
42 / 120
1096 ms16632 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<long long,long long> >vps; int cntdpth=1; long long trg; long long slvmx(int cr=0,int dpth=1){ cntdpth=max(cntdpth,dpth); long long mx=-1ll; if(vps[cr].first<0){ mx=max(mx,vps[cr].first*-1ll); }else{ mx=max(mx,slvmx(vps[cr].first-1,dpth+1)*2ll); } if(vps[cr].second<0){ mx=max(mx,vps[cr].second*-1ll); }else{ mx=max(mx,slvmx(vps[cr].second-1,dpth+1)*2ll); } return mx; } int main() { int n; cin>>n; vps=vector<pair<long long,long long> >(n); for(int i=0;i<n;i++){ long long x,y; cin>>x>>y; vps[i]={x,y}; } trg=2ll*slvmx(); trg+=(trg%(1ll<<cntdpth)==0ll)?0ll:((1ll<<cntdpth)-(trg%cntdpth)); string binary = std::bitset<64>(trg).to_string(); binary.erase(0, binary.find_first_not_of('0')); cout << binary; return 0; } /*** 3 5 4 1 2 4 2 1 3 5 1 2 4 1 5 7 1 2 */
#Verdict Execution timeMemoryGrader output
Fetching results...