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 <vector>
#include <algorithm>
#include <utility>
using namespace std;
int top[2005][2005];
int bottom[2005][2005];
int rangetop[2005][2005], rangebottom[2005][2005];
int f[2005][2005];
const int inf = -100000000;
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (F[i][j]) {
top[i][j] = N;
} else if (i == 0 || F[i-1][j]) {
top[i][j] = i;
} else {
top[i][j] = top[i-1][j];
}
}
}
for (int i = N - 1; i >= 0; i--) {
for (int j = 0; j < N; j++) {
if (F[i][j]) {
bottom[i][j] = -1;
} else if (i == N - 1 || F[i+1][j]) {
bottom[i][j] = i;
} else {
bottom[i][j] = bottom[i+1][j];
}
}
}
int ans = 0;
for (int mrow = 0; mrow < N; mrow++) {
if (N > 500 && mrow != 0 && mrow != N - 1) continue;
for (int i = 0; i < N; i++) {
rangetop[i][i] = top[mrow][i];
rangebottom[i][i] = bottom[mrow][i];
f[i][i] = bottom[mrow][i] - top[mrow][i] + 1;
if (f[i][i] < 0) f[i][i] = -inf;
}
for (int siz = 2; siz <= N; siz++) {
for (int i = 0; i <= N - siz; i++) {
rangetop[i][i+siz-1] = max(rangetop[i+1][i+siz-1], top[mrow][i]);
rangebottom[i][i+siz-1] = min(rangebottom[i+1][i+siz-1], bottom[mrow][i]);
if (rangetop[i][i+siz-1] > rangebottom[i][i+siz-1]) {
f[i][i+siz-1] = -inf;
} else {
f[i][i+siz-1] = max(f[i+1][i+siz-1], f[i][i+siz-2]) + rangebottom[i][i+siz-1] - rangetop[i][i+siz-1] + 1;
ans = max(ans, f[i][i+siz-1]);
}
}
}
}
return ans;
}
# | 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... |