This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
int dp[31][31][31][31];
int a[31];
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
int n=N;
int cnt,x,y;
cnt=x=y=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(F[i][j]){
x=i;
y=j;
cnt++;
}
}
}
if(cnt==1){
return N*N-min(x+1,N-x)*min(y+1,N-y);
}
int res=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
for(int z=j;z<N;z++){
if(F[i][z]){
break;
}
dp[i][i][j][z]=z-j+1;
}
}
}
for(int i=1;i<=N;i++){
for(int j=0;j<N;j++){
int z=j+i-1;
if(j){
for(int l=0;l<N;l++){
vector<pair<int,int>> c;
int sz=0;
int h=l;
for(int r=l;r<N;r++){
if(F[j-1][r]){
if(h!=r){
c.push_back({h,r-1});
a[sz]=0;
sz++;
}
h=r+1;
}
if(!dp[j][z][l][r]){
continue;
}
if(!F[j-1][r]){
dp[j-1][z][h][r]=max(dp[j-1][z][h][r],dp[j][z][l][r]+r-h+1);
}
if(sz){
a[sz-1]=max(a[sz-1],dp[j][z][l][r]);
}
}
h=0;
for(int i=sz-1;i>=0;i--){
h=max(h,a[i]);
if(h==0){
continue;
}
dp[j-1][z][c[i].first][c[i].second]=max(dp[j-1][z][c[i].first][c[i].second],h+c[i].second-c[i].first+1);
}
}
}
if(z+1<N){
for(int l=0;l<N;l++){
vector<pair<int,int>> c;
int sz=0;
int h=l;
for(int r=l;r<N;r++){
if(F[z+1][r]){
if(h!=r){
c.push_back({h,r-1});
a[sz]=0;
sz++;
}
h=r+1;
}
if(!dp[j][z][l][r]){
continue;
}
if(!F[z+1][r]){
dp[j][z+1][h][r]=max(dp[j][z+1][h][r],dp[j][z][l][r]+r-h+1);
}
if(sz){
a[sz-1]=max(a[sz-1],dp[j][z][l][r]);
}
}
h=0;
for(int i=sz-1;i>=0;i--){
h=max(h,a[i]);
if(h==0){
continue;
}
dp[j][z+1][c[i].first][c[i].second]=max(dp[j][z+1][c[i].first][c[i].second],h+c[i].second-c[i].first+1);
}
}
}
}
}
for(int i=0;i<N;i++){
for(int j=i;j<N;j++){
for(int z=0;z<N;z++){
for(int k=z;k<N;k++){
res=max(res,dp[i][j][z][k]);
//cout << i << " " << j << " " << z << " " << k << " " << dp[i][j][z][k] << "\n";
}
}
}
}
return res;
}
Compilation message (stderr)
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:8:9: warning: unused variable 'n' [-Wunused-variable]
8 | int n=N;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |