#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;
}
}
if (cnt == 0) continue; // ignore empty rows
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);
int res = 0;
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;
}
}
}
}
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;
res = max(res, cur);
for (int l2 = l; l2 <= r; l2++) {
for (int r2 = l2; r2 <= r; r2++) {
// update: add 1 row above
if (first_row > 0 && 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 && get_sum(last_row + 1, l2, r2) == 0) {
upMax(dp[first_row][last_row + 1][l2][r2], cur + r2 - l2 + 1);
}
}
}
}
}
}
}
return res;
}
int sub1(int n, const vector<vector<int>>& forest) {
for (int r = 0; r < n; ++r) {
for (int c = 0; c < n; ++c) {
if (forest[r][c] == 1) {
return n * n - min({
(r+1) * (c+1),
(r+1) * (n-c),
(n-r) * (c+1),
(n-r) * (n-c),
});
}
}
}
return n*n;
}
int biggest_stadium(int n, vector<vector<int>> forest) {
auto [is_good, cnt] = subtask_25p(n, forest);
if (is_good) return cnt;
if (n <= 30) return sub4(n, forest);
return sub1(n, forest);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
1 ms |
4956 KB |
ok |
7 |
Correct |
1 ms |
348 KB |
ok |
8 |
Correct |
19 ms |
2396 KB |
ok |
9 |
Correct |
300 ms |
31792 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
4952 KB |
ok |
4 |
Correct |
1 ms |
4956 KB |
ok |
5 |
Correct |
1 ms |
4956 KB |
ok |
6 |
Correct |
1 ms |
4956 KB |
ok |
7 |
Correct |
1 ms |
4956 KB |
ok |
8 |
Correct |
0 ms |
544 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
1 ms |
4956 KB |
ok |
11 |
Correct |
1 ms |
4956 KB |
ok |
12 |
Correct |
1 ms |
4956 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
4952 KB |
ok |
5 |
Correct |
1 ms |
4956 KB |
ok |
6 |
Correct |
1 ms |
4956 KB |
ok |
7 |
Correct |
1 ms |
4956 KB |
ok |
8 |
Correct |
1 ms |
4956 KB |
ok |
9 |
Correct |
0 ms |
544 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
1 ms |
4956 KB |
ok |
12 |
Correct |
1 ms |
4956 KB |
ok |
13 |
Correct |
1 ms |
4956 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
1 ms |
4956 KB |
ok |
16 |
Correct |
1 ms |
4956 KB |
ok |
17 |
Correct |
1 ms |
4956 KB |
ok |
18 |
Correct |
1 ms |
4956 KB |
ok |
19 |
Correct |
1 ms |
4956 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
5208 KB |
ok |
23 |
Correct |
1 ms |
4956 KB |
ok |
24 |
Correct |
1 ms |
4956 KB |
ok |
25 |
Correct |
1 ms |
4956 KB |
ok |
26 |
Correct |
1 ms |
4956 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
1 ms |
4952 KB |
ok |
7 |
Correct |
1 ms |
4956 KB |
ok |
8 |
Correct |
1 ms |
4956 KB |
ok |
9 |
Correct |
1 ms |
4956 KB |
ok |
10 |
Correct |
1 ms |
4956 KB |
ok |
11 |
Correct |
0 ms |
544 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
1 ms |
4956 KB |
ok |
14 |
Correct |
1 ms |
4956 KB |
ok |
15 |
Correct |
1 ms |
4956 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
4956 KB |
ok |
18 |
Correct |
1 ms |
4956 KB |
ok |
19 |
Correct |
1 ms |
4956 KB |
ok |
20 |
Correct |
1 ms |
4956 KB |
ok |
21 |
Correct |
1 ms |
4956 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
5208 KB |
ok |
25 |
Correct |
1 ms |
4956 KB |
ok |
26 |
Correct |
1 ms |
4956 KB |
ok |
27 |
Correct |
1 ms |
4956 KB |
ok |
28 |
Correct |
1 ms |
4956 KB |
ok |
29 |
Correct |
1 ms |
4956 KB |
ok |
30 |
Correct |
2 ms |
4952 KB |
ok |
31 |
Correct |
2 ms |
4956 KB |
ok |
32 |
Correct |
1 ms |
4956 KB |
ok |
33 |
Correct |
1 ms |
4956 KB |
ok |
34 |
Correct |
1 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
1 ms |
5080 KB |
ok |
37 |
Correct |
1 ms |
4956 KB |
ok |
38 |
Correct |
1 ms |
4976 KB |
ok |
39 |
Correct |
3 ms |
5092 KB |
ok |
40 |
Correct |
16 ms |
5088 KB |
ok |
41 |
Correct |
10 ms |
4952 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
1 ms |
4952 KB |
ok |
7 |
Correct |
1 ms |
4956 KB |
ok |
8 |
Correct |
1 ms |
4956 KB |
ok |
9 |
Correct |
1 ms |
4956 KB |
ok |
10 |
Correct |
1 ms |
4956 KB |
ok |
11 |
Correct |
0 ms |
544 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
1 ms |
4956 KB |
ok |
14 |
Correct |
1 ms |
4956 KB |
ok |
15 |
Correct |
1 ms |
4956 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
4956 KB |
ok |
18 |
Correct |
1 ms |
4956 KB |
ok |
19 |
Correct |
1 ms |
4956 KB |
ok |
20 |
Correct |
1 ms |
4956 KB |
ok |
21 |
Correct |
1 ms |
4956 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
5208 KB |
ok |
25 |
Correct |
1 ms |
4956 KB |
ok |
26 |
Correct |
1 ms |
4956 KB |
ok |
27 |
Correct |
1 ms |
4956 KB |
ok |
28 |
Correct |
1 ms |
4956 KB |
ok |
29 |
Correct |
1 ms |
4956 KB |
ok |
30 |
Correct |
2 ms |
4952 KB |
ok |
31 |
Correct |
2 ms |
4956 KB |
ok |
32 |
Correct |
1 ms |
4956 KB |
ok |
33 |
Correct |
1 ms |
4956 KB |
ok |
34 |
Correct |
1 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
1 ms |
5080 KB |
ok |
37 |
Correct |
1 ms |
4956 KB |
ok |
38 |
Correct |
1 ms |
4976 KB |
ok |
39 |
Correct |
3 ms |
5092 KB |
ok |
40 |
Correct |
16 ms |
5088 KB |
ok |
41 |
Correct |
10 ms |
4952 KB |
ok |
42 |
Partially correct |
22 ms |
2196 KB |
partial |
43 |
Partially correct |
19 ms |
2396 KB |
partial |
44 |
Partially correct |
19 ms |
2204 KB |
partial |
45 |
Partially correct |
19 ms |
2396 KB |
partial |
46 |
Partially correct |
19 ms |
2396 KB |
partial |
47 |
Partially correct |
19 ms |
2396 KB |
partial |
48 |
Correct |
19 ms |
2208 KB |
ok |
49 |
Partially correct |
21 ms |
2196 KB |
partial |
50 |
Partially correct |
19 ms |
2396 KB |
partial |
51 |
Partially correct |
19 ms |
2392 KB |
partial |
52 |
Partially correct |
19 ms |
2396 KB |
partial |
53 |
Partially correct |
19 ms |
2204 KB |
partial |
54 |
Partially correct |
22 ms |
2200 KB |
partial |
55 |
Partially correct |
19 ms |
2396 KB |
partial |
56 |
Partially correct |
19 ms |
2392 KB |
partial |
57 |
Partially correct |
19 ms |
2396 KB |
partial |
58 |
Partially correct |
19 ms |
2392 KB |
partial |
59 |
Partially correct |
18 ms |
2648 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4956 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
1 ms |
4956 KB |
ok |
8 |
Correct |
1 ms |
348 KB |
ok |
9 |
Correct |
19 ms |
2396 KB |
ok |
10 |
Correct |
300 ms |
31792 KB |
ok |
11 |
Correct |
1 ms |
4952 KB |
ok |
12 |
Correct |
1 ms |
4956 KB |
ok |
13 |
Correct |
1 ms |
4956 KB |
ok |
14 |
Correct |
1 ms |
4956 KB |
ok |
15 |
Correct |
1 ms |
4956 KB |
ok |
16 |
Correct |
0 ms |
544 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
1 ms |
4956 KB |
ok |
19 |
Correct |
1 ms |
4956 KB |
ok |
20 |
Correct |
1 ms |
4956 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
4956 KB |
ok |
23 |
Correct |
1 ms |
4956 KB |
ok |
24 |
Correct |
1 ms |
4956 KB |
ok |
25 |
Correct |
1 ms |
4956 KB |
ok |
26 |
Correct |
1 ms |
4956 KB |
ok |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
1 ms |
5208 KB |
ok |
30 |
Correct |
1 ms |
4956 KB |
ok |
31 |
Correct |
1 ms |
4956 KB |
ok |
32 |
Correct |
1 ms |
4956 KB |
ok |
33 |
Correct |
1 ms |
4956 KB |
ok |
34 |
Correct |
1 ms |
4956 KB |
ok |
35 |
Correct |
2 ms |
4952 KB |
ok |
36 |
Correct |
2 ms |
4956 KB |
ok |
37 |
Correct |
1 ms |
4956 KB |
ok |
38 |
Correct |
1 ms |
4956 KB |
ok |
39 |
Correct |
1 ms |
348 KB |
ok |
40 |
Correct |
0 ms |
348 KB |
ok |
41 |
Correct |
1 ms |
5080 KB |
ok |
42 |
Correct |
1 ms |
4956 KB |
ok |
43 |
Correct |
1 ms |
4976 KB |
ok |
44 |
Correct |
3 ms |
5092 KB |
ok |
45 |
Correct |
16 ms |
5088 KB |
ok |
46 |
Correct |
10 ms |
4952 KB |
ok |
47 |
Partially correct |
22 ms |
2196 KB |
partial |
48 |
Partially correct |
19 ms |
2396 KB |
partial |
49 |
Partially correct |
19 ms |
2204 KB |
partial |
50 |
Partially correct |
19 ms |
2396 KB |
partial |
51 |
Partially correct |
19 ms |
2396 KB |
partial |
52 |
Partially correct |
19 ms |
2396 KB |
partial |
53 |
Correct |
19 ms |
2208 KB |
ok |
54 |
Partially correct |
21 ms |
2196 KB |
partial |
55 |
Partially correct |
19 ms |
2396 KB |
partial |
56 |
Partially correct |
19 ms |
2392 KB |
partial |
57 |
Partially correct |
19 ms |
2396 KB |
partial |
58 |
Partially correct |
19 ms |
2204 KB |
partial |
59 |
Partially correct |
22 ms |
2200 KB |
partial |
60 |
Partially correct |
19 ms |
2396 KB |
partial |
61 |
Partially correct |
19 ms |
2392 KB |
partial |
62 |
Partially correct |
19 ms |
2396 KB |
partial |
63 |
Partially correct |
19 ms |
2392 KB |
partial |
64 |
Partially correct |
18 ms |
2648 KB |
partial |
65 |
Partially correct |
316 ms |
31824 KB |
partial |
66 |
Partially correct |
316 ms |
31772 KB |
partial |
67 |
Partially correct |
317 ms |
31776 KB |
partial |
68 |
Partially correct |
302 ms |
31776 KB |
partial |
69 |
Partially correct |
304 ms |
31788 KB |
partial |
70 |
Partially correct |
301 ms |
31824 KB |
partial |
71 |
Partially correct |
294 ms |
31772 KB |
partial |
72 |
Partially correct |
302 ms |
31772 KB |
partial |
73 |
Correct |
307 ms |
31772 KB |
ok |
74 |
Correct |
303 ms |
31796 KB |
ok |
75 |
Partially correct |
303 ms |
31788 KB |
partial |
76 |
Partially correct |
300 ms |
31828 KB |
partial |
77 |
Partially correct |
297 ms |
31824 KB |
partial |
78 |
Partially correct |
308 ms |
31664 KB |
partial |
79 |
Partially correct |
311 ms |
31824 KB |
partial |
80 |
Partially correct |
308 ms |
31772 KB |
partial |
81 |
Partially correct |
302 ms |
31768 KB |
partial |
82 |
Partially correct |
309 ms |
31772 KB |
partial |
83 |
Partially correct |
321 ms |
31772 KB |
partial |
84 |
Partially correct |
302 ms |
31780 KB |
partial |
85 |
Partially correct |
303 ms |
31824 KB |
partial |
86 |
Partially correct |
336 ms |
31772 KB |
partial |
87 |
Partially correct |
310 ms |
31828 KB |
partial |
88 |
Partially correct |
314 ms |
31772 KB |
partial |
89 |
Partially correct |
301 ms |
31772 KB |
partial |
90 |
Partially correct |
312 ms |
31828 KB |
partial |
91 |
Partially correct |
302 ms |
31780 KB |
partial |
92 |
Partially correct |
313 ms |
31776 KB |
partial |
93 |
Partially correct |
308 ms |
31776 KB |
partial |
94 |
Partially correct |
308 ms |
31772 KB |
partial |
95 |
Partially correct |
315 ms |
31780 KB |
partial |
96 |
Partially correct |
302 ms |
31792 KB |
partial |
97 |
Partially correct |
305 ms |
31828 KB |
partial |
98 |
Partially correct |
305 ms |
31776 KB |
partial |
99 |
Partially correct |
296 ms |
31780 KB |
partial |
100 |
Partially correct |
296 ms |
31768 KB |
partial |
101 |
Partially correct |
298 ms |
31724 KB |
partial |
102 |
Partially correct |
296 ms |
31828 KB |
partial |
103 |
Partially correct |
295 ms |
31768 KB |
partial |
104 |
Partially correct |
298 ms |
31828 KB |
partial |
105 |
Partially correct |
304 ms |
31824 KB |
partial |
106 |
Partially correct |
293 ms |
31824 KB |
partial |
107 |
Partially correct |
295 ms |
31824 KB |
partial |
108 |
Partially correct |
304 ms |
31828 KB |
partial |
109 |
Partially correct |
315 ms |
31824 KB |
partial |