답안 #763580

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
763580 2023-06-22T13:17:19 Z LucaIlie popa (BOI18_popa) C++17
0 / 100
180 ms 5200 KB
#include "popa.h"
#include <bits/stdc++.h>

using namespace std;

int leftSon[1000], rightSon[1000];
int leftExtend[1000], rightExtend[1000], ind[1000][1000];
bool dp[1000][1000];

void makeTree( int l, int r ) {
    if ( l == r ) {
        leftSon[l] = rightSon[l] = -1;
        return;
    }

    //printf( "%d %d %d\n", l, r, ind[l][r] );
    int k = ind[l][r];
    if ( k == l ) {
        leftSon[k] = -1;
        rightSon[k] = ind[k + 1][r];
        makeTree( k + 1, r );
        return;
    }
    if ( k == r ) {
        leftSon[k] = ind[l][k - 1];
        rightSon[k] = -1;
        makeTree( l, k - 1 );
        return;
    }
    makeTree( l, k - 1 );
    makeTree( k + 1, r );
    leftSon[k] = ind[l][k - 1];
    rightSon[k] = ind[k + 1][r];
}

int solve( int n, int leftt[], int rightt[] ) {
    stack<int> lft;
    for ( int i = 0; i < n; i++ ) {
        leftExtend[i] = i;
        while ( !lft.empty() && query( i, i, lft.top(), i ) ) {
            leftExtend[i] = leftExtend[lft.top()];
            lft.pop();
        }
        lft.push( i );
    }
    stack<int> rght;
    for ( int i = n - 1; i >= 0; i-- ) {
        rightExtend[i] = i;
        while ( !rght.empty() && query( i, i, i, rght.top() ) ) {
            rightExtend[i] = rightExtend[lft.top()];
            rght.pop();
        }
        rght.push( i );
    }

    for ( int i = 0; i < n; i++ ) {
        dp[i][i] = true;
        ind[i][i] = i;
        //printf( "%d: %d %d\n", i, leftExtend[i], rightExtend[i] );
    }
    for ( int len = 2; len <= n; len++ ) {
        for ( int l = 0; l <= n - len; l++ ) {
            int r = l + len - 1;
            for ( int k = l + 1; k <= r - 1; k++ ) {
                if ( leftExtend[k] <= l && r <= rightExtend[k] && dp[l][k - 1] && dp[k + 1][r] ) {
                    dp[l][r] = true;
                    ind[l][r] = k;
                }
            }
            if ( leftExtend[l] <= l && r <= rightExtend[l] && dp[l + 1][r] ) {
                dp[l][r] = true;
                ind[l][r] = l;
            }
            if ( leftExtend[r] <= l && r <= rightExtend[r] && dp[l][r - 1] ) {
                dp[l][r] = true;
                ind[l][r] = r;
            }
            //printf( "%d %d %d\n", l, r, ind[l][r] );
        }
    }

    makeTree( 0, n - 1 );

    for ( int i = 0; i < n; i++ ) {
        leftt[i] = leftSon[i];
        rightt[i] = rightSon[i];
    }

    return ind[0][n - 1];
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 720 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 180 ms 5200 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 308 KB too many queries
2 Halted 0 ms 0 KB -