Submission #61247

# Submission time Handle Problem Language Result Execution time Memory
61247 2018-07-25T13:19:56 Z SpaimaCarpatilor popa (BOI18_popa) C++17
100 / 100
137 ms 640 KB
#include<bits/stdc++.h>
#include "popa.h"

using namespace std;

static int nxt[2018];

int solve (int l, int r, int *Left, int *Right)
{
    if (l > r) return -1;
    if (l == r)
        return l;
    if (r == l + 1)
    {
        if (nxt[l] > r)
        {
            Right[l] = r;
            return l;
        }
        Left[r] = l;
        return r;
    }
    int pos = l;
    while (nxt[pos] <= r)
        pos = nxt[pos];
    int ras = pos;
    Left[ras] = solve (l, ras - 1, Left, Right);
    Right[ras] = solve (ras + 1, r, Left, Right);
    return ras;
}

int solve (int nn, int* Left, int* Right)
{
    int N = nn;
    for (int i=0; i<N; i++)
        Left[i] = Right[i] = -1;
    nxt[N - 1] = N;
    for (int i=N - 2; i>=0; i--)
    {
        int pos = i + 1;
        while (pos < N && query (i, i, i, pos))
            pos = nxt[pos];
        nxt[i] = pos;
    }
    int root = solve (0, N - 1, Left, Right);
    return root;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 248 KB Output is correct
2 Correct 15 ms 308 KB Output is correct
3 Correct 11 ms 384 KB Output is correct
4 Correct 13 ms 420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 556 KB Output is correct
2 Correct 125 ms 624 KB Output is correct
3 Correct 46 ms 624 KB Output is correct
4 Correct 137 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 636 KB Output is correct
2 Correct 95 ms 636 KB Output is correct
3 Correct 76 ms 640 KB Output is correct
4 Correct 86 ms 640 KB Output is correct