# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
763583 |
2023-06-22T13:22:07 Z |
LucaIlie |
popa (BOI18_popa) |
C++17 |
|
778 ms |
5324 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> st;
for ( int i = 0; i < n; i++ ) {
leftExtend[i] = i;
while ( !st.empty() && query( i, i, st.top(), i ) ) {
leftExtend[i] = leftExtend[st.top()];
rightExtend[st.top()] = i - 1;
st.pop();
}
st.push( i );
}
while ( !st.empty() ) {
rightExtend[st.top()] = n - 1;
st.pop();
}
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];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
704 KB |
Output is correct |
2 |
Correct |
8 ms |
720 KB |
Output is correct |
3 |
Correct |
10 ms |
720 KB |
Output is correct |
4 |
Correct |
10 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
732 ms |
5204 KB |
Output is correct |
2 |
Correct |
686 ms |
5204 KB |
Output is correct |
3 |
Correct |
446 ms |
5324 KB |
Output is correct |
4 |
Correct |
727 ms |
5204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
698 ms |
5200 KB |
Output is correct |
2 |
Correct |
690 ms |
5300 KB |
Output is correct |
3 |
Correct |
677 ms |
5196 KB |
Output is correct |
4 |
Correct |
778 ms |
5200 KB |
Output is correct |