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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 30 + 10;
const int INF = 1e9;
int n;
int p[MAXN][MAXN];
int dp[MAXN][MAXN][MAXN][MAXN];
bool bl[MAXN][MAXN][MAXN][MAXN];
inline int sum(int rowB, int colB, int rowE, int colE)
{
return p[rowE][colE] - p[rowB - 1][colE] - p[rowE][colB - 1] + p[rowB - 1][colB - 1];
}
int f(int rowB, int colB, int rowE, int colE)
{
if (colB > colE)
{
return 0;
}
if (rowB == 1 && rowE == n)
{
return 0;
}
if (bl[rowB][colB][rowE][colE])
{
return dp[rowB][colB][rowE][colE];
}
bl[rowB][colB][rowE][colE] = true;
if (rowB > 1 && sum(rowB - 1, colB, rowB - 1, colE) == 0)
{
dp[rowB][colB][rowE][colE] = std::max(dp[rowB][colB][rowE][colE], (colE - colB + 1) + f(rowB - 1, colB, rowE, colE));
}
if (rowE < n && sum(rowE + 1, colB, rowE + 1, colE) == 0)
{
dp[rowB][colB][rowE][colE] = std::max(dp[rowB][colB][rowE][colE], (colE - colB + 1) + f(rowB, colB, rowE + 1, colE));
}
dp[rowB][colB][rowE][colE] = std::max(dp[rowB][colB][rowE][colE], f(rowB, colB + 1, rowE, colE));
dp[rowB][colB][rowE][colE] = std::max(dp[rowB][colB][rowE][colE], f(rowB, colB, rowE, colE - 1));
return dp[rowB][colB][rowE][colE];
}
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
n = N;
for (int i = 1 ; i <= n ; ++i)
{
for (int j = 1 ; j <= n ; ++j)
{
p[i][j] = p[i - 1][j] + p[i][j - 1] - p[i - 1][j - 1] + F[i - 1][j - 1];
}
}
int max = 0;
for (int rowB = 1 ; rowB <= n ; ++rowB)
{
for (int colB = 1 ; colB <= n ; ++colB)
{
for (int rowE = rowB ; rowE <= n ; ++rowE)
{
for (int colE = colB ; colE <= n ; ++colE)
{
if (sum(rowB, colB, rowE, colE) == 0)
{
max = std::max(max, f(rowB, colB, rowE, colE) + (rowE - rowB + 1) * (colE - colB + 1));
}
}
}
}
}
return max;
}
# | 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... |