#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
int n;
vector<vector<int>> A;
int dp[31][31][31][31];
int cur;
int f(int i, int pos, int l, int r)
{
if (i < 0 || i >= n) return 0;
if (l > r) return 0;
if (pos >= n) return 0;
if (dp[i][pos][l][r] != -1) return dp[i][pos][l][r];
vector<int> v;
v.push_back(l - 1);
for (int j = l; j <= r; j++) if (A[i][j]) v.push_back(j);
v.push_back(r + 1);
int res = 0;
for (int j = 1; j < v.size(); j++)
{
if (i <= cur)
{
res = max(res, f(i - 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
res = max(res, f(cur + (pos - (cur - i)) + 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
}
else
{
res = max(res, f(i + 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
res = max(res, f(cur - (pos - (i - cur)) - 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
}
}
return dp[i][pos][l][r] = res;
}
int solve()
{
for (int i = 0; i < 31; i++)
{
for (int j = 0; j < 31; j++)
{
for (int k = 0; k < 31; k++)
{
for (int l = k; l < 31; l++) dp[i][j][k][l] = -1;
}
}
}
return f(cur, 0, 0, n - 1);
}
int biggest_stadium(int N, vector<vector<int>> B)
{
n = N;
A = B;
int c = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
c += A[i][j];
}
}
if (!c) return n * n;
if (c == 1)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (A[i][j])
{
int i1 = n - i - 1, j1 = n - j - 1;
return max(i * n + j * n - i * j, i1 * n + j1 * n - i1 * j1);
}
}
}
}
int res = 0;
for (cur = 0; cur < n; cur++)
{
res = max(res, solve());
}
return res;
}
Compilation message
soccer.cpp: In function 'int f(int, int, int, int)':
soccer.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int j = 1; j < v.size(); j++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Incorrect |
0 ms |
348 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Incorrect |
0 ms |
348 KB |
wrong |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Incorrect |
0 ms |
348 KB |
wrong |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Incorrect |
0 ms |
348 KB |
wrong |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Incorrect |
0 ms |
348 KB |
wrong |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Incorrect |
0 ms |
348 KB |
wrong |
4 |
Halted |
0 ms |
0 KB |
- |