#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
struct Row {
int first, last;
int cnt() const {
return last - first + 1;
}
bool contains(const Row& b) const {
return first <= b.first && b.last <= last;
}
bool operator < (const Row& b) const {
return cnt() > b.cnt();
}
};
pair<bool, int> subtask_25p(int n, const vector<vector<int>>& forest) {
int cnt_row = 0; // number of non-empty rows
int first_row = n, last_row = -1;
int total = 0;
vector<Row> rows;
for (int r = 0; r < n; ++r) {
int cnt = 0; // number of empty cells
int first = n, last = -1; // all empty cells should be in [first, last]
for (int c = 0; c < n; ++c) {
if (forest[r][c] == 0) {
++total;
++cnt;
if (first == n) first = c;
last = c;
}
}
// ignore empty rows
if (cnt == 0) continue;
if (first_row == n) first_row = r;
last_row = r;
++cnt_row;
// Condition: in each row, there should be only 1 sequence of 0
if (cnt != last - first + 1) return {false, -1};
rows.push_back(Row{first, last});
}
// Condition: all rows with empty cells must be consecutive
if (cnt_row != last_row - first_row + 1) return {false, -2};
// From biggest row, each row should contains the row next to (& further away from) it
int largest_row = min_element(rows.begin(), rows.end()) - rows.begin();
for (int i = largest_row; i > 0; --i) {
if (!rows[i].contains(rows[i-1])) return {false, -3};
}
for (int i = largest_row; i + 1 < (int) rows.size(); ++i) {
if (!rows[i].contains(rows[i+1])) return {false, -4};
}
// In decreasing order of size, row should contains next row
sort(rows.begin(), rows.end());
for (int i = 0; i + 1 < (int) rows.size(); ++i) {
if (!rows[i].contains(rows[i+1])) return {false, -5};
}
return {true, total};
}
int dp[33][33][33][33];
void upMax(int& f, int val) {
if (val > f) f = val;
}
int sub4(int n, vector<vector<int>> forest) {
for (int i = 0; i < n; ++i) {
std::partial_sum(forest[i].begin(), forest[i].end(), forest[i].begin());
}
auto get_sum = [&] (int row, int l, int r) { // [l, r]
return forest[row][r] - (l == 0 ? 0 : forest[row][l-1]);
};
memset(dp, -1, sizeof dp);
for (int first_row = n-1; first_row >= 0; --first_row) {
for (int last_row = first_row; last_row < n; ++last_row) {
// base case: only 1 row
if (first_row == last_row) {
for (int l = 0; l < n; ++l) {
for (int r = l; r < n; ++r) {
if (get_sum(first_row, l, r) == 0) {
dp[first_row][first_row][l][r] = r - l + 1;
}
}
}
}
// update: add 1 row above
if (first_row > 0) {
for (int l = 0; l < n; ++l) {
for (int r = l; r < n; ++r) {
int cur = dp[first_row][last_row][l][r];
if (cur < 0) continue;
for (int l2 = l; l2 <= r; l2++) {
for (int r2 = l2; r2 <= r; r2++) {
if (get_sum(first_row - 1, l2, r2) == 0) {
upMax(dp[first_row - 1][last_row][l2][r2], cur + r2 - l2 + 1);
}
}
}
}
}
}
// update: add 1 row below
if (last_row + 1 < n) {
for (int l = 0; l < n; ++l) {
for (int r = l; r < n; ++r) {
int cur = dp[first_row][last_row][l][r];
if (cur < 0) continue;
for (int l2 = l; l2 <= r; l2++) {
for (int r2 = l2; r2 <= r; r2++) {
if (get_sum(last_row + 1, l2, r2) == 0) {
upMax(dp[first_row][last_row + 1][l2][r2], cur + r2 - l2 + 1);
}
}
}
}
}
}
}
}
int res = 0;
for (int r1 = 0; r1 < n; ++r1) {
for (int r2 = r1; r2 < n; ++r2) {
for (int c1 = 0; c1 < n; ++c1) {
for (int c2 = c1; c2 < n; ++c2) {
upMax(res, dp[r1][r2][c1][c2]);
}
}
}
}
return res;
}
int biggest_stadium(int n, vector<vector<int>> forest) {
auto [is_good, cnt] = subtask_25p(n, forest);
if (is_good) return cnt;
if (n <= 7) return sub4(n, forest);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5208 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
600 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
504 KB |
ok |
6 |
Correct |
1 ms |
4952 KB |
ok |
7 |
Partially correct |
1 ms |
344 KB |
partial |
8 |
Partially correct |
18 ms |
2396 KB |
partial |
9 |
Partially correct |
247 ms |
31824 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
1 ms |
4952 KB |
ok |
4 |
Correct |
1 ms |
4952 KB |
ok |
5 |
Correct |
1 ms |
4952 KB |
ok |
6 |
Correct |
1 ms |
4952 KB |
ok |
7 |
Correct |
1 ms |
4952 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
344 KB |
ok |
10 |
Correct |
1 ms |
4952 KB |
ok |
11 |
Correct |
1 ms |
4952 KB |
ok |
12 |
Correct |
4 ms |
4952 KB |
ok |
13 |
Correct |
0 ms |
344 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5208 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
1 ms |
4952 KB |
ok |
5 |
Correct |
1 ms |
4952 KB |
ok |
6 |
Correct |
1 ms |
4952 KB |
ok |
7 |
Correct |
1 ms |
4952 KB |
ok |
8 |
Correct |
1 ms |
4952 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
344 KB |
ok |
11 |
Correct |
1 ms |
4952 KB |
ok |
12 |
Correct |
1 ms |
4952 KB |
ok |
13 |
Correct |
4 ms |
4952 KB |
ok |
14 |
Correct |
0 ms |
344 KB |
ok |
15 |
Correct |
1 ms |
4952 KB |
ok |
16 |
Correct |
1 ms |
4952 KB |
ok |
17 |
Correct |
1 ms |
4952 KB |
ok |
18 |
Correct |
1 ms |
4952 KB |
ok |
19 |
Correct |
1 ms |
4952 KB |
ok |
20 |
Correct |
0 ms |
344 KB |
ok |
21 |
Correct |
1 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
4956 KB |
ok |
23 |
Correct |
1 ms |
4952 KB |
ok |
24 |
Correct |
1 ms |
4956 KB |
ok |
25 |
Correct |
1 ms |
4956 KB |
ok |
26 |
Correct |
1 ms |
4952 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5208 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
600 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
1 ms |
4952 KB |
ok |
7 |
Correct |
1 ms |
4952 KB |
ok |
8 |
Correct |
1 ms |
4952 KB |
ok |
9 |
Correct |
1 ms |
4952 KB |
ok |
10 |
Correct |
1 ms |
4952 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
344 KB |
ok |
13 |
Correct |
1 ms |
4952 KB |
ok |
14 |
Correct |
1 ms |
4952 KB |
ok |
15 |
Correct |
4 ms |
4952 KB |
ok |
16 |
Correct |
0 ms |
344 KB |
ok |
17 |
Correct |
1 ms |
4952 KB |
ok |
18 |
Correct |
1 ms |
4952 KB |
ok |
19 |
Correct |
1 ms |
4952 KB |
ok |
20 |
Correct |
1 ms |
4952 KB |
ok |
21 |
Correct |
1 ms |
4952 KB |
ok |
22 |
Correct |
0 ms |
344 KB |
ok |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
4956 KB |
ok |
25 |
Correct |
1 ms |
4952 KB |
ok |
26 |
Correct |
1 ms |
4956 KB |
ok |
27 |
Correct |
1 ms |
4956 KB |
ok |
28 |
Correct |
1 ms |
4952 KB |
ok |
29 |
Correct |
1 ms |
4952 KB |
ok |
30 |
Partially correct |
0 ms |
344 KB |
partial |
31 |
Partially correct |
1 ms |
500 KB |
partial |
32 |
Partially correct |
0 ms |
344 KB |
partial |
33 |
Partially correct |
0 ms |
344 KB |
partial |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
1 ms |
344 KB |
ok |
36 |
Partially correct |
0 ms |
344 KB |
partial |
37 |
Partially correct |
0 ms |
344 KB |
partial |
38 |
Partially correct |
0 ms |
344 KB |
partial |
39 |
Partially correct |
0 ms |
344 KB |
partial |
40 |
Partially correct |
0 ms |
348 KB |
partial |
41 |
Partially correct |
0 ms |
344 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5208 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
600 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
1 ms |
4952 KB |
ok |
7 |
Correct |
1 ms |
4952 KB |
ok |
8 |
Correct |
1 ms |
4952 KB |
ok |
9 |
Correct |
1 ms |
4952 KB |
ok |
10 |
Correct |
1 ms |
4952 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
344 KB |
ok |
13 |
Correct |
1 ms |
4952 KB |
ok |
14 |
Correct |
1 ms |
4952 KB |
ok |
15 |
Correct |
4 ms |
4952 KB |
ok |
16 |
Correct |
0 ms |
344 KB |
ok |
17 |
Correct |
1 ms |
4952 KB |
ok |
18 |
Correct |
1 ms |
4952 KB |
ok |
19 |
Correct |
1 ms |
4952 KB |
ok |
20 |
Correct |
1 ms |
4952 KB |
ok |
21 |
Correct |
1 ms |
4952 KB |
ok |
22 |
Correct |
0 ms |
344 KB |
ok |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
4956 KB |
ok |
25 |
Correct |
1 ms |
4952 KB |
ok |
26 |
Correct |
1 ms |
4956 KB |
ok |
27 |
Correct |
1 ms |
4956 KB |
ok |
28 |
Correct |
1 ms |
4952 KB |
ok |
29 |
Correct |
1 ms |
4952 KB |
ok |
30 |
Partially correct |
0 ms |
344 KB |
partial |
31 |
Partially correct |
1 ms |
500 KB |
partial |
32 |
Partially correct |
0 ms |
344 KB |
partial |
33 |
Partially correct |
0 ms |
344 KB |
partial |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
1 ms |
344 KB |
ok |
36 |
Partially correct |
0 ms |
344 KB |
partial |
37 |
Partially correct |
0 ms |
344 KB |
partial |
38 |
Partially correct |
0 ms |
344 KB |
partial |
39 |
Partially correct |
0 ms |
344 KB |
partial |
40 |
Partially correct |
0 ms |
348 KB |
partial |
41 |
Partially correct |
0 ms |
344 KB |
partial |
42 |
Partially correct |
16 ms |
2392 KB |
partial |
43 |
Partially correct |
15 ms |
2392 KB |
partial |
44 |
Partially correct |
15 ms |
2392 KB |
partial |
45 |
Partially correct |
15 ms |
2392 KB |
partial |
46 |
Partially correct |
16 ms |
2392 KB |
partial |
47 |
Partially correct |
15 ms |
2208 KB |
partial |
48 |
Correct |
17 ms |
2392 KB |
ok |
49 |
Partially correct |
21 ms |
2392 KB |
partial |
50 |
Partially correct |
15 ms |
2392 KB |
partial |
51 |
Partially correct |
15 ms |
2392 KB |
partial |
52 |
Partially correct |
16 ms |
2392 KB |
partial |
53 |
Partially correct |
16 ms |
2396 KB |
partial |
54 |
Partially correct |
16 ms |
2392 KB |
partial |
55 |
Partially correct |
15 ms |
2392 KB |
partial |
56 |
Partially correct |
15 ms |
2392 KB |
partial |
57 |
Partially correct |
15 ms |
2392 KB |
partial |
58 |
Partially correct |
15 ms |
2392 KB |
partial |
59 |
Partially correct |
15 ms |
2392 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5208 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
600 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
504 KB |
ok |
7 |
Correct |
1 ms |
4952 KB |
ok |
8 |
Partially correct |
1 ms |
344 KB |
partial |
9 |
Partially correct |
18 ms |
2396 KB |
partial |
10 |
Partially correct |
247 ms |
31824 KB |
partial |
11 |
Correct |
1 ms |
4952 KB |
ok |
12 |
Correct |
1 ms |
4952 KB |
ok |
13 |
Correct |
1 ms |
4952 KB |
ok |
14 |
Correct |
1 ms |
4952 KB |
ok |
15 |
Correct |
1 ms |
4952 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
344 KB |
ok |
18 |
Correct |
1 ms |
4952 KB |
ok |
19 |
Correct |
1 ms |
4952 KB |
ok |
20 |
Correct |
4 ms |
4952 KB |
ok |
21 |
Correct |
0 ms |
344 KB |
ok |
22 |
Correct |
1 ms |
4952 KB |
ok |
23 |
Correct |
1 ms |
4952 KB |
ok |
24 |
Correct |
1 ms |
4952 KB |
ok |
25 |
Correct |
1 ms |
4952 KB |
ok |
26 |
Correct |
1 ms |
4952 KB |
ok |
27 |
Correct |
0 ms |
344 KB |
ok |
28 |
Correct |
1 ms |
348 KB |
ok |
29 |
Correct |
1 ms |
4956 KB |
ok |
30 |
Correct |
1 ms |
4952 KB |
ok |
31 |
Correct |
1 ms |
4956 KB |
ok |
32 |
Correct |
1 ms |
4956 KB |
ok |
33 |
Correct |
1 ms |
4952 KB |
ok |
34 |
Correct |
1 ms |
4952 KB |
ok |
35 |
Partially correct |
0 ms |
344 KB |
partial |
36 |
Partially correct |
1 ms |
500 KB |
partial |
37 |
Partially correct |
0 ms |
344 KB |
partial |
38 |
Partially correct |
0 ms |
344 KB |
partial |
39 |
Correct |
0 ms |
348 KB |
ok |
40 |
Correct |
1 ms |
344 KB |
ok |
41 |
Partially correct |
0 ms |
344 KB |
partial |
42 |
Partially correct |
0 ms |
344 KB |
partial |
43 |
Partially correct |
0 ms |
344 KB |
partial |
44 |
Partially correct |
0 ms |
344 KB |
partial |
45 |
Partially correct |
0 ms |
348 KB |
partial |
46 |
Partially correct |
0 ms |
344 KB |
partial |
47 |
Partially correct |
16 ms |
2392 KB |
partial |
48 |
Partially correct |
15 ms |
2392 KB |
partial |
49 |
Partially correct |
15 ms |
2392 KB |
partial |
50 |
Partially correct |
15 ms |
2392 KB |
partial |
51 |
Partially correct |
16 ms |
2392 KB |
partial |
52 |
Partially correct |
15 ms |
2208 KB |
partial |
53 |
Correct |
17 ms |
2392 KB |
ok |
54 |
Partially correct |
21 ms |
2392 KB |
partial |
55 |
Partially correct |
15 ms |
2392 KB |
partial |
56 |
Partially correct |
15 ms |
2392 KB |
partial |
57 |
Partially correct |
16 ms |
2392 KB |
partial |
58 |
Partially correct |
16 ms |
2396 KB |
partial |
59 |
Partially correct |
16 ms |
2392 KB |
partial |
60 |
Partially correct |
15 ms |
2392 KB |
partial |
61 |
Partially correct |
15 ms |
2392 KB |
partial |
62 |
Partially correct |
15 ms |
2392 KB |
partial |
63 |
Partially correct |
15 ms |
2392 KB |
partial |
64 |
Partially correct |
15 ms |
2392 KB |
partial |
65 |
Partially correct |
250 ms |
31772 KB |
partial |
66 |
Partially correct |
247 ms |
31776 KB |
partial |
67 |
Partially correct |
246 ms |
31780 KB |
partial |
68 |
Partially correct |
238 ms |
31772 KB |
partial |
69 |
Partially correct |
241 ms |
31824 KB |
partial |
70 |
Partially correct |
236 ms |
31772 KB |
partial |
71 |
Partially correct |
241 ms |
31776 KB |
partial |
72 |
Partially correct |
244 ms |
31772 KB |
partial |
73 |
Correct |
236 ms |
31824 KB |
ok |
74 |
Correct |
248 ms |
31824 KB |
ok |
75 |
Partially correct |
239 ms |
31820 KB |
partial |
76 |
Partially correct |
235 ms |
31780 KB |
partial |
77 |
Partially correct |
249 ms |
31824 KB |
partial |
78 |
Partially correct |
249 ms |
31776 KB |
partial |
79 |
Partially correct |
262 ms |
31780 KB |
partial |
80 |
Partially correct |
239 ms |
31780 KB |
partial |
81 |
Partially correct |
238 ms |
31824 KB |
partial |
82 |
Partially correct |
238 ms |
31768 KB |
partial |
83 |
Partially correct |
246 ms |
31824 KB |
partial |
84 |
Partially correct |
240 ms |
31776 KB |
partial |
85 |
Partially correct |
274 ms |
31772 KB |
partial |
86 |
Partially correct |
241 ms |
31824 KB |
partial |
87 |
Partially correct |
245 ms |
31776 KB |
partial |
88 |
Partially correct |
245 ms |
31888 KB |
partial |
89 |
Partially correct |
245 ms |
31824 KB |
partial |
90 |
Partially correct |
245 ms |
31824 KB |
partial |
91 |
Partially correct |
246 ms |
31768 KB |
partial |
92 |
Partially correct |
245 ms |
31768 KB |
partial |
93 |
Partially correct |
256 ms |
31776 KB |
partial |
94 |
Partially correct |
249 ms |
31828 KB |
partial |
95 |
Partially correct |
242 ms |
31768 KB |
partial |
96 |
Partially correct |
247 ms |
31776 KB |
partial |
97 |
Partially correct |
240 ms |
31772 KB |
partial |
98 |
Partially correct |
248 ms |
31824 KB |
partial |
99 |
Partially correct |
248 ms |
31756 KB |
partial |
100 |
Partially correct |
235 ms |
31780 KB |
partial |
101 |
Partially correct |
242 ms |
31776 KB |
partial |
102 |
Partially correct |
249 ms |
31824 KB |
partial |
103 |
Partially correct |
256 ms |
31772 KB |
partial |
104 |
Partially correct |
241 ms |
31772 KB |
partial |
105 |
Partially correct |
258 ms |
31824 KB |
partial |
106 |
Partially correct |
242 ms |
31824 KB |
partial |
107 |
Partially correct |
251 ms |
31776 KB |
partial |
108 |
Partially correct |
246 ms |
31824 KB |
partial |
109 |
Partially correct |
237 ms |
31824 KB |
partial |