#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
const int mxn=2006;
int n,res,dp[mxn][mxn],l[mxn][mxn],r[mxn][mxn],u[mxn][mxn],d[mxn][mxn],ch[mxn][mxn],a[mxn][mxn],b[mxn][mxn];
vector <int> ve[mxn][mxn];
int f(int i, int j){
if (dp[i][j]!=-1)
return dp[i][j];
if (j!=l[i][j])
return dp[i][j]=f(i,l[i][j]);
dp[i][j]=0;
int sz=r[i][j]-l[i][j]+1;
for (int k:ve[i][j])
dp[i][j]=max(dp[i][j],f(k,j)-sz*(d[k][j]-u[k][j]+1));
dp[i][j]+=sz*(d[i][j]-u[i][j]+1);
return dp[i][j];
}
int solve(vector <vector <int>> F){
for (int i=0;i<n;i++){
for (int j=0;j<n;j++){
l[i][j]=(j&&!F[i][j-1]?l[i][j-1]:j);
u[i][j]=0;
d[i][j]=n-1;
}
for (int j=n;j;j--)
r[i][j-1]=(j<n&&!F[i][j]?r[i][j]:j-1);
}
memset(a,-1,sizeof(a));
memset(b,-1,sizeof(b));
for (int j=0;j<n;j++){
stack <int> st;
for (int i=0;i<n;i++){
if (F[i][j]){
while (!st.empty()){
d[st.top()][j]=i-1;
st.pop();
}
continue;
}
while (!st.empty()&&(l[i][j]>l[st.top()][j]||r[i][j]<r[st.top()][j])){
d[st.top()][j]=i-1;
st.pop();
}
if (!st.empty()){
if (r[i][j]-l[i][j]==r[st.top()][j]-l[st.top()][j]){
a[i][j]=st.top();
continue;
}
ve[st.top()][j].push_back(i);
}
ch[i][j]=1;
st.push(i);
}
while (!st.empty())
st.pop();
for (int i=n-1;i>=0;i--){
if (F[i][j]){
while (!st.empty()){
u[st.top()][j]=i+1;
st.pop();
}
continue;
}
while (!st.empty()&&(l[i][j]>l[st.top()][j]||r[i][j]<r[st.top()][j])){
u[st.top()][j]=i+1;
st.pop();
}
if (!st.empty()){
if (r[i][j]-l[i][j]==r[st.top()][j]-l[st.top()][j]){
b[i][j]=st.top();
continue;
}
ve[st.top()][j].push_back(i);
}
ch[i][j]=1;
st.push(i);
}
}
for (int i=0;i<n;i++)
for (int j=0;j<n;j++){
if (a[i][j]>=0)
d[i][j]=d[a[i][j]][j];
if (b[i][j]>=0)
u[i][j]=u[b[i][j]][j];
}
memset(dp,-1,sizeof(dp));
int ans=0;
for (int i=0;i<n;i++)
for (int j=0;j<n;j++)
if (ch[i][j])
ans=max(ans,f(i,j));
return ans;
}
int biggest_stadium(int N, vector <vector <int>> F){
n=N;
res=solve(F);
for (int i=0;i<n;i++)
for (int j=i;j<n;j++)
swap(F[i][j],F[j][i]);
return max(res,solve(F));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
155220 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
155128 KB |
ok |
2 |
Correct |
33 ms |
155248 KB |
ok |
3 |
Correct |
35 ms |
155436 KB |
ok |
4 |
Incorrect |
34 ms |
155144 KB |
wrong |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
155128 KB |
ok |
2 |
Correct |
33 ms |
155248 KB |
ok |
3 |
Correct |
33 ms |
155228 KB |
ok |
4 |
Correct |
34 ms |
155112 KB |
ok |
5 |
Correct |
34 ms |
155100 KB |
ok |
6 |
Partially correct |
32 ms |
155224 KB |
partial |
7 |
Partially correct |
33 ms |
155216 KB |
partial |
8 |
Correct |
32 ms |
155224 KB |
ok |
9 |
Correct |
33 ms |
155228 KB |
ok |
10 |
Correct |
33 ms |
155124 KB |
ok |
11 |
Incorrect |
33 ms |
155228 KB |
wrong |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
155220 KB |
ok |
2 |
Correct |
33 ms |
155128 KB |
ok |
3 |
Correct |
33 ms |
155248 KB |
ok |
4 |
Correct |
33 ms |
155228 KB |
ok |
5 |
Correct |
34 ms |
155112 KB |
ok |
6 |
Correct |
34 ms |
155100 KB |
ok |
7 |
Partially correct |
32 ms |
155224 KB |
partial |
8 |
Partially correct |
33 ms |
155216 KB |
partial |
9 |
Correct |
32 ms |
155224 KB |
ok |
10 |
Correct |
33 ms |
155228 KB |
ok |
11 |
Correct |
33 ms |
155124 KB |
ok |
12 |
Incorrect |
33 ms |
155228 KB |
wrong |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
155220 KB |
ok |
2 |
Correct |
33 ms |
155128 KB |
ok |
3 |
Correct |
33 ms |
155248 KB |
ok |
4 |
Correct |
35 ms |
155436 KB |
ok |
5 |
Incorrect |
34 ms |
155144 KB |
wrong |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
155220 KB |
ok |
2 |
Correct |
33 ms |
155128 KB |
ok |
3 |
Correct |
33 ms |
155248 KB |
ok |
4 |
Correct |
35 ms |
155436 KB |
ok |
5 |
Incorrect |
34 ms |
155144 KB |
wrong |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
155220 KB |
ok |
2 |
Correct |
33 ms |
155128 KB |
ok |
3 |
Correct |
33 ms |
155248 KB |
ok |
4 |
Correct |
35 ms |
155436 KB |
ok |
5 |
Incorrect |
34 ms |
155144 KB |
wrong |
6 |
Halted |
0 ms |
0 KB |
- |