#include <iostream>
#include <vector>
using namespace std;
const int N = 30;
int n;
int tree[2000][2000];
bool seen[2000][2000];
int prefix[N][N];
int dp1[N][N][N];
int dp2[N][N][N];
bool are_empty(int row, int col1, int col2) {
if (col1 == 0) {
return prefix[row][col2] == 0;
}
return prefix[row][col2] == prefix[row][col1 - 1];
}
int solve_1() {
int x = 0;
int y = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (tree[i][j] == 1) {
x = i;
y = j;
}
}
}
x += 1;
y += 1;
int m = x * y;
int t = x * (n - y + 1);
if (t < m) {
m = t;
}
t = (n - x + 1) * y;
if (t < m) {
m = t;
}
t = (n - x + 1) * (n - y + 1);
if (t < m) {
m = t;
}
return n * n - m;
}
int dp() {
// init
for (int i = 0; i < n; i++) {
prefix[i][0] = tree[i][0];
for (int j = 1; j < n; j++) {
prefix[i][j] = prefix[i][j - 1] + tree[i][j];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
dp1[i][j][k] = -1;
dp2[i][j][k] = -1;
}
}
}
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
// if all empty
if (are_empty(0, j, k)) {
dp1[0][j][k] = k - j + 1;
}
}
}
// dp from 1 to n - 1
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
// check base case
if (are_empty(i, j, k)) {
dp1[i][j][k] = k - j + 1;
} else {
continue;
}
for (int l = j; l <= k; l++) {
for (int m = l; m <= k; m++) {
// check if [l, m] are all empty
if (!are_empty(i - 1, l, m)) {
break;
}
// dp1
if (dp1[i - 1][l][m] != -1) {
int t = dp1[i - 1][l][m] + k - j + 1;
if (dp1[i][j][k] == -1 || dp1[i][j][k] < t) {
dp1[i][j][k] = t;
}
}
}
}
}
}
}
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
// if all empty
if (are_empty(n - 1, j, k)) {
dp2[n - 1][j][k] = k - j + 1;
}
}
}
// dp from n - 2 to 0
for (int i = n - 2; i >= 0; i--) {
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
// check base case
if (are_empty(i, j, k)) {
dp2[i][j][k] = k - j + 1;
} else {
continue;
}
for (int l = j; l <= k; l++) {
for (int m = l; m <= k; m++) {
// check if [l, m] are all empty
if (!are_empty(i + 1, l, m)) {
break;
}
// dp2
if (dp2[i + 1][l][m] != -1) {
int t = dp2[i + 1][l][m] + k - j + 1;
if (dp2[i][j][k] == -1 || dp2[i][j][k] < t) {
dp2[i][j][k] = t;
}
}
}
}
}
}
}
/*for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
cout << i << " " << j << " " << k << " " << dp1[i][j][k] << "\n";
}
}
}*/
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = j; k < n; k++) {
if (ans < dp1[i][j][k]) {
ans = dp1[i][j][k];
}
if (ans < dp2[i][j][k]) {
ans = dp2[i][j][k];
}
/*if (dp1[i][j][k] != -1 && dp2[i][j][k] != -1) {
int t = dp1[i][j][k] + dp2[i][j][k] - (k - j + 1);
if (t > ans) {
ans = t;
}
}*/
}
}
}
return ans;
}
void dfs(int r, int c) {
seen[r][c] = true;
if (r - 1 >= 0 && tree[r - 1][c] == 0 && !seen[r - 1][c]) {
dfs(r - 1, c);
}
if (r + 1 < n && tree[r + 1][c] == 0 && !seen[r + 1][c]) {
dfs(r + 1, c);
}
if (c - 1 >= 0 && tree[r][c - 1] == 0 && !seen[r][c - 1]) {
dfs(r, c - 1);
}
if (c + 1 < n && tree[r][c + 1] == 0 && !seen[r][c + 1]) {
dfs(r, c + 1);
}
}
bool check() {
int c = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
seen[i][j] = false;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (tree[i][j] == 0) {
if (!seen[i][j]) {
dfs(i, j);
c += 1;
}
}
}
}
if (c != 1) {
return false;
}
vector<int> s;
vector<int> t;
int longest = 0;
int where = 0;
for (int i = 0; i < n; i++) {
bool seen = false;
for (int j = 0; j < n;) {
if (tree[i][j] == 0) {
if (seen) {
return false;
}
seen = true;
int k = j + 1;
while (k < n && tree[i][k] == 0) {
k++;
}
s.push_back(j);
t.push_back(k - 1);
if (longest < k - j) {
longest = k - j;
where = i;
}
j = k;
} else {
j++;
}
}
}
for (int i = where - 1; i >= 0; i--) {
if (s[i] < s[i + 1] || t[i] > t[i + 1]) {
return false;
}
}
for (int i = where; i + 1 < n; i++) {
if (s[i + 1] < s[i] || t[i + 1] > t[i]) {
return false;
}
}
for (int i = 0; i < s.size(); i++) {
for (int j = i + 1; j < s.size(); j++) {
if (!(s[i] <= s[j] && t[j] <= t[i]
|| s[j] <= s[i] && t[i] <= t[j]
)) {
return false;
}
}
}
return true;
}
// int biggest_stadium(int N, int[][] F)
int biggest_stadium(int X, vector<vector<int>> F) {
n = X;
int total = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
tree[i][j] = F[i][j];
total += tree[i][j];
}
}
if (total == 1) {
return solve_1();
}
if (total == 0) {
return n * n;
}
/*if (n > 30) {
return 123;
}*/
if (check()) {
return n * n - total;
}
return 0;
/*int ans = dp();
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int t = tree[i][j];
tree[i][j] = tree[j][i];
tree[j][i] = t;
}
}
int another_ans = dp();
if (another_ans > ans) {
ans = another_ans;
}
return ans;*/
}
Compilation message
soccer.cpp: In function 'bool check()':
soccer.cpp:250:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
250 | for (int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
soccer.cpp:251:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
251 | for (int j = i + 1; j < s.size(); j++) {
| ~~^~~~~~~~~~
soccer.cpp:252:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
252 | if (!(s[i] <= s[j] && t[j] <= t[i]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ok |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Correct |
0 ms |
340 KB |
ok |
4 |
Correct |
0 ms |
340 KB |
ok |
5 |
Correct |
0 ms |
212 KB |
ok |
6 |
Correct |
1 ms |
212 KB |
ok |
7 |
Correct |
1 ms |
724 KB |
ok |
8 |
Correct |
20 ms |
5148 KB |
ok |
9 |
Correct |
254 ms |
47384 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
ok |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Partially correct |
0 ms |
340 KB |
partial |
4 |
Partially correct |
0 ms |
212 KB |
partial |
5 |
Partially correct |
0 ms |
212 KB |
partial |
6 |
Partially correct |
0 ms |
212 KB |
partial |
7 |
Partially correct |
0 ms |
212 KB |
partial |
8 |
Correct |
0 ms |
212 KB |
ok |
9 |
Correct |
0 ms |
212 KB |
ok |
10 |
Partially correct |
0 ms |
340 KB |
partial |
11 |
Partially correct |
0 ms |
340 KB |
partial |
12 |
Partially correct |
0 ms |
340 KB |
partial |
13 |
Correct |
0 ms |
340 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
partial |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Correct |
0 ms |
212 KB |
ok |
4 |
Partially correct |
0 ms |
340 KB |
partial |
5 |
Partially correct |
0 ms |
212 KB |
partial |
6 |
Partially correct |
0 ms |
212 KB |
partial |
7 |
Partially correct |
0 ms |
212 KB |
partial |
8 |
Partially correct |
0 ms |
212 KB |
partial |
9 |
Correct |
0 ms |
212 KB |
ok |
10 |
Correct |
0 ms |
212 KB |
ok |
11 |
Partially correct |
0 ms |
340 KB |
partial |
12 |
Partially correct |
0 ms |
340 KB |
partial |
13 |
Partially correct |
0 ms |
340 KB |
partial |
14 |
Correct |
0 ms |
340 KB |
ok |
15 |
Partially correct |
0 ms |
340 KB |
partial |
16 |
Partially correct |
1 ms |
340 KB |
partial |
17 |
Partially correct |
0 ms |
340 KB |
partial |
18 |
Partially correct |
0 ms |
340 KB |
partial |
19 |
Partially correct |
0 ms |
340 KB |
partial |
20 |
Incorrect |
0 ms |
340 KB |
wrong |
21 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
partial |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Correct |
0 ms |
212 KB |
ok |
4 |
Correct |
0 ms |
340 KB |
ok |
5 |
Correct |
0 ms |
340 KB |
ok |
6 |
Partially correct |
0 ms |
340 KB |
partial |
7 |
Partially correct |
0 ms |
212 KB |
partial |
8 |
Partially correct |
0 ms |
212 KB |
partial |
9 |
Partially correct |
0 ms |
212 KB |
partial |
10 |
Partially correct |
0 ms |
212 KB |
partial |
11 |
Correct |
0 ms |
212 KB |
ok |
12 |
Correct |
0 ms |
212 KB |
ok |
13 |
Partially correct |
0 ms |
340 KB |
partial |
14 |
Partially correct |
0 ms |
340 KB |
partial |
15 |
Partially correct |
0 ms |
340 KB |
partial |
16 |
Correct |
0 ms |
340 KB |
ok |
17 |
Partially correct |
0 ms |
340 KB |
partial |
18 |
Partially correct |
1 ms |
340 KB |
partial |
19 |
Partially correct |
0 ms |
340 KB |
partial |
20 |
Partially correct |
0 ms |
340 KB |
partial |
21 |
Partially correct |
0 ms |
340 KB |
partial |
22 |
Incorrect |
0 ms |
340 KB |
wrong |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
partial |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Correct |
0 ms |
212 KB |
ok |
4 |
Correct |
0 ms |
340 KB |
ok |
5 |
Correct |
0 ms |
340 KB |
ok |
6 |
Partially correct |
0 ms |
340 KB |
partial |
7 |
Partially correct |
0 ms |
212 KB |
partial |
8 |
Partially correct |
0 ms |
212 KB |
partial |
9 |
Partially correct |
0 ms |
212 KB |
partial |
10 |
Partially correct |
0 ms |
212 KB |
partial |
11 |
Correct |
0 ms |
212 KB |
ok |
12 |
Correct |
0 ms |
212 KB |
ok |
13 |
Partially correct |
0 ms |
340 KB |
partial |
14 |
Partially correct |
0 ms |
340 KB |
partial |
15 |
Partially correct |
0 ms |
340 KB |
partial |
16 |
Correct |
0 ms |
340 KB |
ok |
17 |
Partially correct |
0 ms |
340 KB |
partial |
18 |
Partially correct |
1 ms |
340 KB |
partial |
19 |
Partially correct |
0 ms |
340 KB |
partial |
20 |
Partially correct |
0 ms |
340 KB |
partial |
21 |
Partially correct |
0 ms |
340 KB |
partial |
22 |
Incorrect |
0 ms |
340 KB |
wrong |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
partial |
2 |
Correct |
0 ms |
212 KB |
ok |
3 |
Correct |
0 ms |
212 KB |
ok |
4 |
Correct |
0 ms |
340 KB |
ok |
5 |
Correct |
0 ms |
340 KB |
ok |
6 |
Correct |
0 ms |
212 KB |
ok |
7 |
Correct |
1 ms |
212 KB |
ok |
8 |
Correct |
1 ms |
724 KB |
ok |
9 |
Correct |
20 ms |
5148 KB |
ok |
10 |
Correct |
254 ms |
47384 KB |
ok |
11 |
Partially correct |
0 ms |
340 KB |
partial |
12 |
Partially correct |
0 ms |
212 KB |
partial |
13 |
Partially correct |
0 ms |
212 KB |
partial |
14 |
Partially correct |
0 ms |
212 KB |
partial |
15 |
Partially correct |
0 ms |
212 KB |
partial |
16 |
Correct |
0 ms |
212 KB |
ok |
17 |
Correct |
0 ms |
212 KB |
ok |
18 |
Partially correct |
0 ms |
340 KB |
partial |
19 |
Partially correct |
0 ms |
340 KB |
partial |
20 |
Partially correct |
0 ms |
340 KB |
partial |
21 |
Correct |
0 ms |
340 KB |
ok |
22 |
Partially correct |
0 ms |
340 KB |
partial |
23 |
Partially correct |
1 ms |
340 KB |
partial |
24 |
Partially correct |
0 ms |
340 KB |
partial |
25 |
Partially correct |
0 ms |
340 KB |
partial |
26 |
Partially correct |
0 ms |
340 KB |
partial |
27 |
Incorrect |
0 ms |
340 KB |
wrong |
28 |
Halted |
0 ms |
0 KB |
- |