# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
763568 |
2023-06-22T13:04:41 Z |
LucaIlie |
popa (BOI18_popa) |
C++17 |
|
361 ms |
5204 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[] ) {
for ( int i = 0; i < n; i++ ) {
int j = i;
while ( j - 1 >= 0 && query( i, i, j - 1, i ) ) {
j--;
int k = leftExtend[j];
while ( j - 1 >= k ) {
j--;
k = min( k, leftExtend[j] );
}
}
leftExtend[i] = j;
}
for ( int i = 0; i < n; i++ ) {
int j = i;
while ( j + 1 < n && query( i, i, i, j + 1 ) ) {
j++;
int k = rightExtend[j];
while ( j + 1 <= k ) {
j++;
k = max( k, rightExtend[j] );
}
}
rightExtend[i] = j;
}
for ( int i = 0; i < n; i++ ) {
dp[i][i] = true;
ind[i][i] = 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];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
700 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
361 ms |
5204 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
300 KB |
too many queries |
2 |
Halted |
0 ms |
0 KB |
- |