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;
const int maxN = 2e3 + 20;
int A[maxN][maxN];
int prv[maxN][maxN][2];
int top[maxN][maxN];
int bottom[maxN][maxN];
vector<pair<int, int>> group[maxN];
int dp[maxN][maxN];
int biggest_stadium(int N, vector<vector<int>> _A) {
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
A[i][j] = _A[i - 1][j - 1];
}
}
for (int i = 0; i <= N + 1; i++) {
A[0][i] = 1;
A[N + 1][i] = 1;
A[i][0] = 1;
A[i][N + 1] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
for (int k = 0; k < 2; k++) {
if (A[i][j] == k) {
prv[i][j][k] = j;
}
else {
prv[i][j][k] = prv[i][j - 1][k];
}
}
}
}
for (int j = 0; j <= N; j++) {
top[0][j] = 0;
bottom[N + 1][j] = N + 1;
}
for (int i = 1; i <= N + 1; i++) {
for (int j = 0; j <= N + 1; j++) {
if (A[i - 1][j] == 1) {
top[i][j] = i - 1;
}
else {
top[i][j] = top[i - 1][j];
}
}
}
for (int i = N; i >= 1; i--) {
for (int j = 0; j <= N; j++) {
if (A[i + 1][j] == 1) {
bottom[i][j] = i + 1;
}
else {
bottom[i][j] = bottom[i + 1][j];
}
}
}
for (int i = N; i >= 1; i--) {
for (int j = 1; j <= N; j++) {
if (A[i][j] == 0) {
if (A[i][j - 1] == 0) {
top[i][j] = max(top[i][j], top[i][j - 1]);
bottom[i][j] = min(bottom[i][j], bottom[i][j - 1]);
}
group[j - prv[i][j][1]].emplace_back(i, j);
}
}
}
int res = 0;
for (int W = N; W >= 1; W--) {
for (auto [i, j]: group[W]) {
/* if (top[i][j] + 1 <= top[i][prv[i][j][1]]) {
dp[top[i][prv[i][j][1]]][j] = max(dp[top[i][prv[i][j][1]]][j], dp[i][j]);
continue;
}*/
int L = prv[i][j][1] + 1;
int R = j;
int T = top[i][j] + 1;
int B = bottom[i][j] - 1;
if (top[B + 1][R + 1] + 1 <= T) {
continue;
}
res = max(res, dp[i][j] + (R - L + 1) * (B - T + 1));
for (int iter = 0; iter < 2; iter++) {
int row = (iter ? B + 1 : T - 1);
if (row < 1 || row > N) {
continue;
}
int nxtR = prv[row][R][0];
while (nxtR >= L) {
int nxtL = max(L, prv[row][nxtR][1] + 1);
int nxt_row = (nxtL == L ? i : row);
dp[nxt_row][nxtR] = max(dp[nxt_row][nxtR], dp[i][j] + ((R - L + 1) - (nxtR - nxtL + 1)) * (B - T + 1));
nxtR = prv[row][nxtL - 1][0];
}
}
}
}
return res;
}
# | 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... |