Submission #315399

#TimeUsernameProblemLanguageResultExecution timeMemory
315399Ahmad_HasanPoklon (COCI17_poklon7)C++17
12 / 120
1088 ms20984 KiB
#include <bits/stdc++.h>

using namespace std;

vector<pair<int,int> >vps;
int cntdpth=1;

int ans=0;
int trg;
int slvmx(int cr=0,int dpth=1){
    cntdpth=max(cntdpth,dpth);
    int mx=-1;
    if(vps[cr].first<0){
        mx=max(mx,vps[cr].first*-1);
    }else{
        mx=max(mx,slvmx(vps[cr].first-1,dpth+1)*2);
    }
    if(vps[cr].second<0){
        mx=max(mx,vps[cr].second*-1);
    }else{
        mx=max(mx,slvmx(vps[cr].second-1,dpth+1)*2);
    }
    return mx;
}

int main()
{
    int n;
    cin>>n;
    vps=vector<pair<int,int> >(n);
    for(int i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        vps[i]={x,y};
    }
    trg=2*slvmx();
    trg+=(trg%(1<<cntdpth)==0)?0:((1<<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...