Submission #241019

# Submission time Handle Problem Language Result Execution time Memory
241019 2020-06-22T08:15:04 Z SamAnd Poklon (COCI17_poklon7) C++17
0 / 120
328 ms 16376 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006;

int n;
int l[N], r[N];

int d[N];

void dfs(int x)
{
    if (l[x] > 0)
    {
        d[l[x]] = d[x] + 1;
        dfs(l[x]);
    }
    if (r[x] > 0)
    {
        d[r[x]] = d[x] + 1;
        dfs(r[x]);
    }
}

void solv()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        scanf("%d%d", &l[i], &r[i]);
    }
    assert(n == 1);
    dfs(1);
    int maxd = 0;
    for (int i = 1; i <= n; ++i)
        maxd = max(maxd, d[i]);
    int maxu = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (l[i] < 0)
        {
            int ymax = -l[i];
            for (int j = d[i]; j < maxd; ++j)
            {
                if (ymax == 1)
                    break;
                ymax = (ymax / 2) + (ymax % 2);
            }
            maxu = max(maxu, ymax);
        }
        if (r[i] < 0)
        {
            int ymax = -r[i];
            for (int j = d[i]; j < maxd; ++j)
            {
                if (ymax == 1)
                    break;
                ymax = (ymax / 2) + (ymax % 2);
            }
            maxu = max(maxu, ymax);
        }
    }
    vector<int> v;
    while (maxu)
    {
        v.push_back(maxu % 2);
        maxu /= 2;
    }
    reverse(all(v));
    for (int i = 0; i < v.size(); ++i)
        printf("%d", v[i]);
    for (int i = 0; i <= maxd; ++i)
        printf("0");
    printf("\n");
}

int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    //ios_base::sync_with_stdio(false), cin.tie(0);
    solv();
    return 0;
}

//while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}

Compilation message

poklon.cpp: In function 'void solv()':
poklon.cpp:77:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < v.size(); ++i)
                     ~~^~~~~~~~~~
poklon.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
poklon.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &l[i], &r[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 6 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 6 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 8 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Runtime error 9 ms 768 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Runtime error 22 ms 1408 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Runtime error 37 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
15 Runtime error 37 ms 2040 KB Execution killed with signal 11 (could be triggered by violating memory limits)
16 Runtime error 116 ms 5880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
17 Runtime error 266 ms 13304 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Runtime error 267 ms 13304 KB Execution killed with signal 11 (could be triggered by violating memory limits)
19 Runtime error 328 ms 16356 KB Execution killed with signal 11 (could be triggered by violating memory limits)
20 Runtime error 307 ms 16376 KB Execution killed with signal 11 (could be triggered by violating memory limits)