Submission #1183773

#TimeUsernameProblemLanguageResultExecution timeMemory
1183773xtlPoklon (COCI17_poklon7)C++20
120 / 120
200 ms87440 KiB
#include <bits/stdc++.h>
using namespace std;
int N;
int L[1000001];
int R[1000001];
double best = 0;
int mBest, dBest;
void dfs(int v, int depth)
{
    if (L[v] < 0 && best < log2(-L[v]) + depth)
    {
        best = log2(-L[v]) + depth;
        mBest = -L[v];
        dBest = depth;
    }
    if (R[v] < 0 && best < log2(-R[v]) + depth)
    {
        best = log2(-R[v]) + depth;
        mBest = -R[v];
        dBest = depth;
    }
    if (L[v] > 0)
        dfs(L[v], depth + 1);
    if (R[v] > 0)
        dfs(R[v], depth + 1);
}
int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> L[i] >> R[i];
    dfs(1, 1);
    int count = 0;
    while ((mBest) >> count)
        count++;
    bitset<32> x(mBest);
    while (count > 0)
    {
        cout << x[count - 1];
        count--;
    }
    while (dBest)
    {
        cout << 0;
        dBest--;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...