#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2020;
int n;
int f[N][N], qs[N][N];
int l[N], r[N];
// check if all empty cell are regular stadium
bool all_can() {
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= n + 1;j++) {
if (f[i][j - 1] != f[i][j]) {
if (!l[i]) l[i] = j;
else if (!r[i]) r[i] = j - 1;
else return 0;
}
}
}
for (int j = 1;j <= n;j++) {
int cnt = 0;
for (int i = 1;i <= n;i++) {
cnt += f[i - 1][j] != f[i][j];
}
if (cnt > 2) return 0;
}
for (int i = 1;i <= n;i++) {
if (l[i] == 0) continue;
for (int j = 1;j <= n;j++) {
if (l[j] == 0) continue;
bool ch = (l[i] <= l[j] && r[j] <= r[i]) || (l[j] <= l[i] && r[i] <= r[j]);
if (!ch) return 0;
}
}
return 1;
}
int dp[33][33][33][33], mx;
int biggest_stadium(int NN, vector<vector<int>> F) {
n = NN;
int empty_cell = 0;
for (int i = 1;i <= n;i++) {
f[0][i] = f[n + 1][i] = f[i][0] = f[i][n + 1] = 1;
for (int j = 1;j <= n;j++) {
f[i][j] = F[i - 1][j - 1];
qs[i][j] = qs[i][j - 1] + f[i][j];
empty_cell += f[i][j] == 0;
}
}
if (all_can()) return empty_cell;
if (empty_cell == n * n - 1) {
int mx = 0;
for (int i = 1;i <= n && !mx;i++) {
for (int j = 1;j <= n && !mx;j++) {
if (f[i][j]) {
mx = max(mx, (i - 1) * n + (j - 1) * n - (i - 1) * (j - 1));
mx = max(mx, (n - i) * n + (j - 1) * n - (n - i) * (j - 1));
mx = max(mx, (i - 1) * n + (n - j) * n - (i - 1) * (n - j));
mx = max(mx, (n - i) * n + (n - j) * n - (n - i) * (n - j));
}
}
}
return mx;
}
if (n > 30) return 0;
// dp[i][j][l][r] -> soccer stadium from i -> j can only place in (l, r) interval
memset(dp, 0xc0, sizeof dp);
// Base Case
for (int i = 1;i <= n;i++) {
for (int l = 1;l <= n;l++) {
for (int r = l;r <= n;r++) {
if (qs[i][r] - qs[i][l - 1] == 0) dp[i][i][l][r] = r - l + 1;
}
}
}
// Calcualte DP
for (int k = 1;k < n;k++) {
for (int i = 1;i <= n - k;i++) {
int j = i + k;
for (int l = 1;l <= n;l++) {
for (int r = l;r <= n;r++) {
int& v = dp[i][j][l][r];
for (int l1 = 1;l1 <= l;l1++) {
for (int r1 = r;r1 <= n;r1++) {
if (qs[j][r] - qs[j][l - 1] == 0)
v = max(v, dp[i][j - 1][l1][r1] + r - l + 1);
if (qs[i][r] - qs[i][l - 1] == 0)
v = max(v, dp[i + 1][j][l1][r1] + r - l + 1);
}
}
}
}
}
}
for (int i = 1;i <= n;i++) for (int j = 1;j <= n;j++)
for (int l = 1;l <= n;l++) for (int r = 1;r <= n;r++) {
mx = max(mx, dp[i][j][l][r]);
}
return mx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
1372 KB |
ok |
8 |
Correct |
15 ms |
8796 KB |
ok |
9 |
Correct |
228 ms |
70484 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
2 ms |
4952 KB |
ok |
4 |
Correct |
2 ms |
4952 KB |
ok |
5 |
Correct |
2 ms |
5052 KB |
ok |
6 |
Correct |
2 ms |
5052 KB |
ok |
7 |
Correct |
2 ms |
4956 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
2 ms |
5108 KB |
ok |
11 |
Correct |
3 ms |
5116 KB |
ok |
12 |
Correct |
3 ms |
5056 KB |
ok |
13 |
Correct |
0 ms |
452 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
2 ms |
4952 KB |
ok |
5 |
Correct |
2 ms |
4952 KB |
ok |
6 |
Correct |
2 ms |
5052 KB |
ok |
7 |
Correct |
2 ms |
5052 KB |
ok |
8 |
Correct |
2 ms |
4956 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
2 ms |
5108 KB |
ok |
12 |
Correct |
3 ms |
5116 KB |
ok |
13 |
Correct |
3 ms |
5056 KB |
ok |
14 |
Correct |
0 ms |
452 KB |
ok |
15 |
Correct |
2 ms |
4952 KB |
ok |
16 |
Correct |
2 ms |
4956 KB |
ok |
17 |
Correct |
2 ms |
4956 KB |
ok |
18 |
Correct |
2 ms |
4952 KB |
ok |
19 |
Correct |
2 ms |
4956 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
2 ms |
4956 KB |
ok |
23 |
Correct |
2 ms |
4956 KB |
ok |
24 |
Correct |
2 ms |
4956 KB |
ok |
25 |
Correct |
2 ms |
5056 KB |
ok |
26 |
Correct |
2 ms |
4956 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Correct |
2 ms |
4952 KB |
ok |
7 |
Correct |
2 ms |
4952 KB |
ok |
8 |
Correct |
2 ms |
5052 KB |
ok |
9 |
Correct |
2 ms |
5052 KB |
ok |
10 |
Correct |
2 ms |
4956 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
2 ms |
5108 KB |
ok |
14 |
Correct |
3 ms |
5116 KB |
ok |
15 |
Correct |
3 ms |
5056 KB |
ok |
16 |
Correct |
0 ms |
452 KB |
ok |
17 |
Correct |
2 ms |
4952 KB |
ok |
18 |
Correct |
2 ms |
4956 KB |
ok |
19 |
Correct |
2 ms |
4956 KB |
ok |
20 |
Correct |
2 ms |
4952 KB |
ok |
21 |
Correct |
2 ms |
4956 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
2 ms |
4956 KB |
ok |
25 |
Correct |
2 ms |
4956 KB |
ok |
26 |
Correct |
2 ms |
4956 KB |
ok |
27 |
Correct |
2 ms |
5056 KB |
ok |
28 |
Correct |
2 ms |
4956 KB |
ok |
29 |
Correct |
2 ms |
4956 KB |
ok |
30 |
Correct |
36 ms |
5212 KB |
ok |
31 |
Correct |
27 ms |
5212 KB |
ok |
32 |
Correct |
26 ms |
5212 KB |
ok |
33 |
Correct |
25 ms |
5364 KB |
ok |
34 |
Correct |
0 ms |
600 KB |
ok |
35 |
Correct |
0 ms |
600 KB |
ok |
36 |
Correct |
35 ms |
5340 KB |
ok |
37 |
Correct |
29 ms |
5208 KB |
ok |
38 |
Correct |
26 ms |
5212 KB |
ok |
39 |
Correct |
27 ms |
5212 KB |
ok |
40 |
Correct |
29 ms |
5212 KB |
ok |
41 |
Correct |
31 ms |
5208 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Correct |
2 ms |
4952 KB |
ok |
7 |
Correct |
2 ms |
4952 KB |
ok |
8 |
Correct |
2 ms |
5052 KB |
ok |
9 |
Correct |
2 ms |
5052 KB |
ok |
10 |
Correct |
2 ms |
4956 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
2 ms |
5108 KB |
ok |
14 |
Correct |
3 ms |
5116 KB |
ok |
15 |
Correct |
3 ms |
5056 KB |
ok |
16 |
Correct |
0 ms |
452 KB |
ok |
17 |
Correct |
2 ms |
4952 KB |
ok |
18 |
Correct |
2 ms |
4956 KB |
ok |
19 |
Correct |
2 ms |
4956 KB |
ok |
20 |
Correct |
2 ms |
4952 KB |
ok |
21 |
Correct |
2 ms |
4956 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
2 ms |
4956 KB |
ok |
25 |
Correct |
2 ms |
4956 KB |
ok |
26 |
Correct |
2 ms |
4956 KB |
ok |
27 |
Correct |
2 ms |
5056 KB |
ok |
28 |
Correct |
2 ms |
4956 KB |
ok |
29 |
Correct |
2 ms |
4956 KB |
ok |
30 |
Correct |
36 ms |
5212 KB |
ok |
31 |
Correct |
27 ms |
5212 KB |
ok |
32 |
Correct |
26 ms |
5212 KB |
ok |
33 |
Correct |
25 ms |
5364 KB |
ok |
34 |
Correct |
0 ms |
600 KB |
ok |
35 |
Correct |
0 ms |
600 KB |
ok |
36 |
Correct |
35 ms |
5340 KB |
ok |
37 |
Correct |
29 ms |
5208 KB |
ok |
38 |
Correct |
26 ms |
5212 KB |
ok |
39 |
Correct |
27 ms |
5212 KB |
ok |
40 |
Correct |
29 ms |
5212 KB |
ok |
41 |
Correct |
31 ms |
5208 KB |
ok |
42 |
Partially correct |
14 ms |
8796 KB |
partial |
43 |
Partially correct |
15 ms |
8792 KB |
partial |
44 |
Partially correct |
14 ms |
9052 KB |
partial |
45 |
Partially correct |
14 ms |
8796 KB |
partial |
46 |
Partially correct |
21 ms |
8708 KB |
partial |
47 |
Partially correct |
14 ms |
8788 KB |
partial |
48 |
Correct |
15 ms |
8852 KB |
ok |
49 |
Partially correct |
15 ms |
8788 KB |
partial |
50 |
Partially correct |
15 ms |
8792 KB |
partial |
51 |
Partially correct |
14 ms |
8796 KB |
partial |
52 |
Partially correct |
14 ms |
8796 KB |
partial |
53 |
Partially correct |
15 ms |
8796 KB |
partial |
54 |
Partially correct |
20 ms |
9048 KB |
partial |
55 |
Partially correct |
15 ms |
8796 KB |
partial |
56 |
Partially correct |
15 ms |
8800 KB |
partial |
57 |
Partially correct |
17 ms |
8792 KB |
partial |
58 |
Partially correct |
14 ms |
8796 KB |
partial |
59 |
Partially correct |
14 ms |
8796 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
1372 KB |
ok |
9 |
Correct |
15 ms |
8796 KB |
ok |
10 |
Correct |
228 ms |
70484 KB |
ok |
11 |
Correct |
2 ms |
4952 KB |
ok |
12 |
Correct |
2 ms |
4952 KB |
ok |
13 |
Correct |
2 ms |
5052 KB |
ok |
14 |
Correct |
2 ms |
5052 KB |
ok |
15 |
Correct |
2 ms |
4956 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
2 ms |
5108 KB |
ok |
19 |
Correct |
3 ms |
5116 KB |
ok |
20 |
Correct |
3 ms |
5056 KB |
ok |
21 |
Correct |
0 ms |
452 KB |
ok |
22 |
Correct |
2 ms |
4952 KB |
ok |
23 |
Correct |
2 ms |
4956 KB |
ok |
24 |
Correct |
2 ms |
4956 KB |
ok |
25 |
Correct |
2 ms |
4952 KB |
ok |
26 |
Correct |
2 ms |
4956 KB |
ok |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
2 ms |
4956 KB |
ok |
30 |
Correct |
2 ms |
4956 KB |
ok |
31 |
Correct |
2 ms |
4956 KB |
ok |
32 |
Correct |
2 ms |
5056 KB |
ok |
33 |
Correct |
2 ms |
4956 KB |
ok |
34 |
Correct |
2 ms |
4956 KB |
ok |
35 |
Correct |
36 ms |
5212 KB |
ok |
36 |
Correct |
27 ms |
5212 KB |
ok |
37 |
Correct |
26 ms |
5212 KB |
ok |
38 |
Correct |
25 ms |
5364 KB |
ok |
39 |
Correct |
0 ms |
600 KB |
ok |
40 |
Correct |
0 ms |
600 KB |
ok |
41 |
Correct |
35 ms |
5340 KB |
ok |
42 |
Correct |
29 ms |
5208 KB |
ok |
43 |
Correct |
26 ms |
5212 KB |
ok |
44 |
Correct |
27 ms |
5212 KB |
ok |
45 |
Correct |
29 ms |
5212 KB |
ok |
46 |
Correct |
31 ms |
5208 KB |
ok |
47 |
Partially correct |
14 ms |
8796 KB |
partial |
48 |
Partially correct |
15 ms |
8792 KB |
partial |
49 |
Partially correct |
14 ms |
9052 KB |
partial |
50 |
Partially correct |
14 ms |
8796 KB |
partial |
51 |
Partially correct |
21 ms |
8708 KB |
partial |
52 |
Partially correct |
14 ms |
8788 KB |
partial |
53 |
Correct |
15 ms |
8852 KB |
ok |
54 |
Partially correct |
15 ms |
8788 KB |
partial |
55 |
Partially correct |
15 ms |
8792 KB |
partial |
56 |
Partially correct |
14 ms |
8796 KB |
partial |
57 |
Partially correct |
14 ms |
8796 KB |
partial |
58 |
Partially correct |
15 ms |
8796 KB |
partial |
59 |
Partially correct |
20 ms |
9048 KB |
partial |
60 |
Partially correct |
15 ms |
8796 KB |
partial |
61 |
Partially correct |
15 ms |
8800 KB |
partial |
62 |
Partially correct |
17 ms |
8792 KB |
partial |
63 |
Partially correct |
14 ms |
8796 KB |
partial |
64 |
Partially correct |
14 ms |
8796 KB |
partial |
65 |
Partially correct |
197 ms |
70480 KB |
partial |
66 |
Partially correct |
218 ms |
70480 KB |
partial |
67 |
Partially correct |
268 ms |
70508 KB |
partial |
68 |
Partially correct |
191 ms |
70480 KB |
partial |
69 |
Partially correct |
200 ms |
70692 KB |
partial |
70 |
Partially correct |
219 ms |
70552 KB |
partial |
71 |
Partially correct |
211 ms |
70484 KB |
partial |
72 |
Partially correct |
201 ms |
70484 KB |
partial |
73 |
Correct |
219 ms |
70652 KB |
ok |
74 |
Correct |
229 ms |
70556 KB |
ok |
75 |
Partially correct |
228 ms |
70636 KB |
partial |
76 |
Partially correct |
211 ms |
70548 KB |
partial |
77 |
Partially correct |
213 ms |
70480 KB |
partial |
78 |
Partially correct |
199 ms |
70680 KB |
partial |
79 |
Partially correct |
207 ms |
70484 KB |
partial |
80 |
Partially correct |
209 ms |
70692 KB |
partial |
81 |
Partially correct |
194 ms |
70484 KB |
partial |
82 |
Partially correct |
211 ms |
70544 KB |
partial |
83 |
Partially correct |
216 ms |
70484 KB |
partial |
84 |
Partially correct |
216 ms |
70484 KB |
partial |
85 |
Partially correct |
255 ms |
69460 KB |
partial |
86 |
Partially correct |
247 ms |
69532 KB |
partial |
87 |
Partially correct |
219 ms |
69440 KB |
partial |
88 |
Partially correct |
220 ms |
69456 KB |
partial |
89 |
Partially correct |
204 ms |
69672 KB |
partial |
90 |
Partially correct |
213 ms |
69652 KB |
partial |
91 |
Partially correct |
205 ms |
69460 KB |
partial |
92 |
Partially correct |
208 ms |
69460 KB |
partial |
93 |
Partially correct |
231 ms |
69648 KB |
partial |
94 |
Partially correct |
205 ms |
69544 KB |
partial |
95 |
Partially correct |
210 ms |
69460 KB |
partial |
96 |
Partially correct |
211 ms |
69456 KB |
partial |
97 |
Partially correct |
208 ms |
69456 KB |
partial |
98 |
Partially correct |
202 ms |
69456 KB |
partial |
99 |
Partially correct |
207 ms |
69520 KB |
partial |
100 |
Partially correct |
201 ms |
69456 KB |
partial |
101 |
Partially correct |
206 ms |
69664 KB |
partial |
102 |
Partially correct |
204 ms |
69660 KB |
partial |
103 |
Partially correct |
219 ms |
67548 KB |
partial |
104 |
Partially correct |
208 ms |
67424 KB |
partial |
105 |
Partially correct |
211 ms |
67408 KB |
partial |
106 |
Partially correct |
225 ms |
67468 KB |
partial |
107 |
Partially correct |
230 ms |
67408 KB |
partial |
108 |
Partially correct |
200 ms |
67408 KB |
partial |
109 |
Partially correct |
219 ms |
67392 KB |
partial |