#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
int dp[8000006];
int biggest_stadium(int N, vector<vector<int>> F) {
int n = N;
vector<vector<int>> a = F, next(n, vector<int>(n)), sum(n, vector<int>(n));
map<vector<int>, int> mp;
vector<vector<int>> v(n), vv;
function<int(int, int, int, int)> summ = [&] (int l, int r, int x, int y) {
long long ans = sum[y][r];
if (x - 1 >= 0) ans -= sum[x - 1][r];
if (l - 1 >= 0) ans -= sum[y][l - 1];
if (x - 1 >= 0 && l - 1 >= 0) ans += sum[x - 1][l - 1];
return ans;
};
int cnt = 0;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
sum[i][j] += a[i][j];
if (j) sum[i][j] += sum[i][j - 1];
if (a[i][j] == 0) v[i].push_back(j);
}
v[i].push_back(n + 1);
}
for (int i = 1; i < n; i ++) {
for (int j = 0; j < n; j ++) sum[i][j] += sum[i - 1][j];
}
for (int i = 0; i < n; i ++) {
if (a[i][n - 1] == 0) next[i][n - 1] = n - 1;
else next[i][n - 1] = n - 2;
for (int j = n - 2; j >= 0; j --) {
if (a[i][j]) next[i][j] = j - 1;
else next[i][j] = next[i][j + 1];
}
}
int ans = 0;
for (int i = 0; i < n; i ++) {
for (int j = 0; j < n; j ++) {
if (a[i][j]) continue;
int ll = i, rr = n, mid, x, y;
while (ll < rr) {
mid = (ll + rr) / 2;
if (summ(j, next[i][j], i, mid) == 0) ll = mid + 1;
else rr = mid;
}
ll --;
y = ll;
ll = 0, rr = i;
while (ll < rr) {
mid = (ll + rr) / 2;
if (summ(j, next[i][j], mid, i) == 0) rr = mid;
else ll = mid + 1;
}
x = ll;
vector<int> vvv = {j, next[i][j], x, y};
if (mp[vvv] == 0) {
vv.push_back(vvv);
mp[vvv] = ++ cnt;
}
j = next[i][j];
}
}
function<bool(vector<int>, vector<int>)> cmp = [&](vector<int> a, vector<int> b) {
int siz1 = (a[1] - a[0] + 1), siz2 = (b[1] - b[0] + 1);
int siz3 = (a[3] - a[2] + 1), siz4 = (b[3] - b[2] + 1);
if (siz1 > siz2 && siz3 < siz4) return 1;
return 0;
};
sort(vv.begin(), vv.end(), cmp);
for (auto xx : vv) {
if (mp.count(xx) == 0) mp[xx] = ++ cnt;
int id = mp[xx];
dp[id] = max(dp[id], (xx[1] - xx[0] + 1) * (xx[3] - xx[2] + 1));
ans = max(ans, dp[id]);
int l = xx[0], r = xx[1], x = xx[2], y = xx[3];
if (x - 1 >= 0) {
for (int j = l; j <= r; j ++) {
int z = min(r, next[x - 1][j]);
if (a[x - 1][j] == 0) {
int ll = y, rr = n, mid, nx, ny;
while (ll < rr) {
mid = (ll + rr) / 2;
if (summ(j, z, x, mid) == 0) ll = mid + 1;
else rr = mid;
}
ll --;
ny = ll;
ll = 0, rr = x;
while (ll < rr) {
mid = (ll + rr) / 2;
if (summ(j, z, mid, y) == 0) rr = mid;
else ll = mid + 1;
}
nx = ll;
vector<int> xxx = {j, z, nx, ny};
if (mp.count(xxx) == 0) mp[xxx] = ++ cnt;
int idd = mp[xxx];
dp[idd] = max(dp[idd], dp[id] + (z - j + 1) * (x - nx + ny - y));
}
j = *upper_bound(v[x - 1].begin(), v[x - 1].end(), z) - 1;
}
}
if (y + 1 < n) {
for (int j = l; j <= r; j ++) {
int z = min(r, next[y + 1][j]);
if (a[y + 1][j] == 0) {
int ll = y, rr = n, mid, nx, ny;
while (ll < rr) {
mid = (ll + rr) / 2;
if (summ(j, z, x, mid) == 0) ll = mid + 1;
else rr = mid;
}
ll --;
ny = ll;
ll = 0, rr = x;
while (ll < rr) {
mid = (ll + rr) / 2;
if (summ(j, z, mid, y) == 0) rr = mid;
else ll = mid + 1;
}
nx = ll;
vector<int> xxx = {j, z, nx, ny};
if (mp.count(xxx) == 0) mp[xxx] = ++ cnt;
int idd = mp[xxx];
dp[idd] = max(dp[idd], dp[id] + (z - j + 1) * (x - nx + ny - y));
}
j = *upper_bound(v[y + 1].begin(), v[y + 1].end(), z) - 1;
}
}
}
return ans;
}
/*
3
0 0 0
0 1 0
0 0 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
604 KB |
ok |
8 |
Correct |
13 ms |
6236 KB |
ok |
9 |
Correct |
230 ms |
95008 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
364 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Partially correct |
0 ms |
348 KB |
partial |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
1 ms |
344 KB |
ok |
13 |
Correct |
1 ms |
344 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
364 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Partially correct |
0 ms |
348 KB |
partial |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
1 ms |
344 KB |
ok |
14 |
Correct |
1 ms |
344 KB |
ok |
15 |
Correct |
0 ms |
344 KB |
ok |
16 |
Partially correct |
0 ms |
348 KB |
partial |
17 |
Partially correct |
0 ms |
348 KB |
partial |
18 |
Partially correct |
1 ms |
344 KB |
partial |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
344 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
0 ms |
348 KB |
partial |
26 |
Partially correct |
0 ms |
348 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
344 KB |
ok |
8 |
Correct |
0 ms |
364 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Partially correct |
0 ms |
348 KB |
partial |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
1 ms |
344 KB |
ok |
16 |
Correct |
1 ms |
344 KB |
ok |
17 |
Correct |
0 ms |
344 KB |
ok |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Partially correct |
1 ms |
344 KB |
partial |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
344 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
0 ms |
348 KB |
ok |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Partially correct |
0 ms |
348 KB |
partial |
28 |
Partially correct |
0 ms |
348 KB |
partial |
29 |
Partially correct |
0 ms |
348 KB |
partial |
30 |
Correct |
0 ms |
348 KB |
ok |
31 |
Partially correct |
1 ms |
348 KB |
partial |
32 |
Correct |
1 ms |
344 KB |
ok |
33 |
Correct |
0 ms |
348 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
0 ms |
348 KB |
ok |
37 |
Partially correct |
0 ms |
348 KB |
partial |
38 |
Partially correct |
0 ms |
348 KB |
partial |
39 |
Partially correct |
1 ms |
348 KB |
partial |
40 |
Correct |
1 ms |
348 KB |
ok |
41 |
Partially correct |
0 ms |
348 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
344 KB |
ok |
8 |
Correct |
0 ms |
364 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Partially correct |
0 ms |
348 KB |
partial |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
1 ms |
344 KB |
ok |
16 |
Correct |
1 ms |
344 KB |
ok |
17 |
Correct |
0 ms |
344 KB |
ok |
18 |
Partially correct |
0 ms |
348 KB |
partial |
19 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Partially correct |
1 ms |
344 KB |
partial |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
344 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
0 ms |
348 KB |
ok |
26 |
Partially correct |
0 ms |
348 KB |
partial |
27 |
Partially correct |
0 ms |
348 KB |
partial |
28 |
Partially correct |
0 ms |
348 KB |
partial |
29 |
Partially correct |
0 ms |
348 KB |
partial |
30 |
Correct |
0 ms |
348 KB |
ok |
31 |
Partially correct |
1 ms |
348 KB |
partial |
32 |
Correct |
1 ms |
344 KB |
ok |
33 |
Correct |
0 ms |
348 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
0 ms |
348 KB |
ok |
37 |
Partially correct |
0 ms |
348 KB |
partial |
38 |
Partially correct |
0 ms |
348 KB |
partial |
39 |
Partially correct |
1 ms |
348 KB |
partial |
40 |
Correct |
1 ms |
348 KB |
ok |
41 |
Partially correct |
0 ms |
348 KB |
partial |
42 |
Partially correct |
107 ms |
12804 KB |
partial |
43 |
Partially correct |
130 ms |
15316 KB |
partial |
44 |
Partially correct |
28 ms |
7508 KB |
partial |
45 |
Partially correct |
31 ms |
6812 KB |
partial |
46 |
Partially correct |
60 ms |
10172 KB |
partial |
47 |
Partially correct |
15 ms |
6236 KB |
partial |
48 |
Correct |
15 ms |
6052 KB |
ok |
49 |
Partially correct |
15 ms |
5976 KB |
partial |
50 |
Correct |
49 ms |
6048 KB |
ok |
51 |
Partially correct |
41 ms |
9368 KB |
partial |
52 |
Partially correct |
18 ms |
5468 KB |
partial |
53 |
Partially correct |
15 ms |
5448 KB |
partial |
54 |
Partially correct |
14 ms |
5468 KB |
partial |
55 |
Partially correct |
15 ms |
5724 KB |
partial |
56 |
Correct |
17 ms |
5796 KB |
ok |
57 |
Partially correct |
16 ms |
6572 KB |
partial |
58 |
Partially correct |
22 ms |
6568 KB |
partial |
59 |
Partially correct |
15 ms |
6488 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
604 KB |
ok |
9 |
Correct |
13 ms |
6236 KB |
ok |
10 |
Correct |
230 ms |
95008 KB |
ok |
11 |
Correct |
0 ms |
344 KB |
ok |
12 |
Correct |
0 ms |
344 KB |
ok |
13 |
Correct |
0 ms |
364 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Partially correct |
0 ms |
348 KB |
partial |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
1 ms |
344 KB |
ok |
21 |
Correct |
1 ms |
344 KB |
ok |
22 |
Correct |
0 ms |
344 KB |
ok |
23 |
Partially correct |
0 ms |
348 KB |
partial |
24 |
Partially correct |
0 ms |
348 KB |
partial |
25 |
Partially correct |
1 ms |
344 KB |
partial |
26 |
Correct |
0 ms |
348 KB |
ok |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
344 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
0 ms |
348 KB |
ok |
31 |
Partially correct |
0 ms |
348 KB |
partial |
32 |
Partially correct |
0 ms |
348 KB |
partial |
33 |
Partially correct |
0 ms |
348 KB |
partial |
34 |
Partially correct |
0 ms |
348 KB |
partial |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Partially correct |
1 ms |
348 KB |
partial |
37 |
Correct |
1 ms |
344 KB |
ok |
38 |
Correct |
0 ms |
348 KB |
ok |
39 |
Correct |
0 ms |
348 KB |
ok |
40 |
Correct |
0 ms |
348 KB |
ok |
41 |
Correct |
0 ms |
348 KB |
ok |
42 |
Partially correct |
0 ms |
348 KB |
partial |
43 |
Partially correct |
0 ms |
348 KB |
partial |
44 |
Partially correct |
1 ms |
348 KB |
partial |
45 |
Correct |
1 ms |
348 KB |
ok |
46 |
Partially correct |
0 ms |
348 KB |
partial |
47 |
Partially correct |
107 ms |
12804 KB |
partial |
48 |
Partially correct |
130 ms |
15316 KB |
partial |
49 |
Partially correct |
28 ms |
7508 KB |
partial |
50 |
Partially correct |
31 ms |
6812 KB |
partial |
51 |
Partially correct |
60 ms |
10172 KB |
partial |
52 |
Partially correct |
15 ms |
6236 KB |
partial |
53 |
Correct |
15 ms |
6052 KB |
ok |
54 |
Partially correct |
15 ms |
5976 KB |
partial |
55 |
Correct |
49 ms |
6048 KB |
ok |
56 |
Partially correct |
41 ms |
9368 KB |
partial |
57 |
Partially correct |
18 ms |
5468 KB |
partial |
58 |
Partially correct |
15 ms |
5448 KB |
partial |
59 |
Partially correct |
14 ms |
5468 KB |
partial |
60 |
Partially correct |
15 ms |
5724 KB |
partial |
61 |
Correct |
17 ms |
5796 KB |
ok |
62 |
Partially correct |
16 ms |
6572 KB |
partial |
63 |
Partially correct |
22 ms |
6568 KB |
partial |
64 |
Partially correct |
15 ms |
6488 KB |
partial |
65 |
Partially correct |
3371 ms |
199604 KB |
partial |
66 |
Partially correct |
2997 ms |
212428 KB |
partial |
67 |
Partially correct |
1141 ms |
137336 KB |
partial |
68 |
Partially correct |
249 ms |
97364 KB |
partial |
69 |
Partially correct |
603 ms |
112596 KB |
partial |
70 |
Partially correct |
1069 ms |
130264 KB |
partial |
71 |
Partially correct |
238 ms |
96288 KB |
partial |
72 |
Partially correct |
221 ms |
95060 KB |
partial |
73 |
Correct |
258 ms |
89936 KB |
ok |
74 |
Correct |
219 ms |
89940 KB |
ok |
75 |
Partially correct |
218 ms |
89940 KB |
partial |
76 |
Correct |
845 ms |
91288 KB |
ok |
77 |
Correct |
825 ms |
91520 KB |
ok |
78 |
Partially correct |
578 ms |
121332 KB |
partial |
79 |
Partially correct |
400 ms |
91352 KB |
partial |
80 |
Partially correct |
364 ms |
87764 KB |
partial |
81 |
Partially correct |
342 ms |
88040 KB |
partial |
82 |
Partially correct |
459 ms |
95488 KB |
partial |
83 |
Partially correct |
1344 ms |
130088 KB |
partial |
84 |
Partially correct |
249 ms |
81232 KB |
partial |
85 |
Partially correct |
257 ms |
80420 KB |
partial |
86 |
Partially correct |
241 ms |
82260 KB |
partial |
87 |
Partially correct |
257 ms |
82740 KB |
partial |
88 |
Correct |
239 ms |
86104 KB |
ok |
89 |
Partially correct |
232 ms |
95204 KB |
partial |
90 |
Partially correct |
256 ms |
95056 KB |
partial |
91 |
Partially correct |
227 ms |
93780 KB |
partial |
92 |
Partially correct |
865 ms |
112628 KB |
partial |
93 |
Correct |
850 ms |
118148 KB |
ok |
94 |
Partially correct |
403 ms |
93184 KB |
partial |
95 |
Correct |
323 ms |
87296 KB |
ok |
96 |
Partially correct |
286 ms |
85220 KB |
partial |
97 |
Partially correct |
271 ms |
84108 KB |
partial |
98 |
Partially correct |
262 ms |
81552 KB |
partial |
99 |
Correct |
946 ms |
134264 KB |
ok |
100 |
Partially correct |
283 ms |
96036 KB |
partial |
101 |
Partially correct |
233 ms |
96036 KB |
partial |
102 |
Partially correct |
250 ms |
96084 KB |
partial |
103 |
Partially correct |
234 ms |
96084 KB |
partial |
104 |
Partially correct |
227 ms |
96080 KB |
partial |
105 |
Partially correct |
244 ms |
96080 KB |
partial |
106 |
Partially correct |
251 ms |
96080 KB |
partial |
107 |
Partially correct |
260 ms |
96084 KB |
partial |
108 |
Partially correct |
480 ms |
102668 KB |
partial |
109 |
Partially correct |
429 ms |
102112 KB |
partial |