#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
const int N=2005;
int n;
int a[N][N];
int top[N][N],bot[N][N],pre[N][N][2],dp[N][N];
vector<pair<int,int>> rect[N];
int ans;
int biggest_stadium(int _n,vector<vector<int>> _a){
n=_n;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)a[i][j]=_a[i-1][j-1]^1;
for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)top[i][j]=a[i][j]?a[i-1][j]?top[i-1][j]:i:top[i-1][j];
for(int i=1;i<=n;i++)bot[n+1][i]=n+1;
for(int i=n;i>=1;i--)for(int j=1;j<=n;j++)bot[i][j]=a[i][j]?a[i+1][j]?bot[i+1][j]:i:bot[i+1][j];
for(int i=1;i<=n;i++){
int t=0,b=n+1;
for(int j=1;j<=n;j++){
for(int x=0;x<2;x++)pre[i][j][x]=a[i][j]==x?j:pre[i][j-1][x];
if(a[i][j]){
if(a[i][j-1]){
top[i][j]=max(top[i][j],top[i][j-1]);
bot[i][j]=min(bot[i][j],bot[i][j-1]);
}
rect[j-pre[i][j][0]].emplace_back(i,j);
}
}
}
for(int w=n;w>=1;w--)for(auto [i,j]:rect[w]){
int l=pre[i][j][0]+1,r=j,t=top[i][j],b=bot[i][j];
if(a[i][j+1]&&top[i][j+1]<=t&&bot[i][j+1]>=b)continue;
int lw=l>1?bot[i][l-1]+1:i+1;
if(lw<=b){
dp[lw][j]=max(dp[lw][j],dp[i][j]);
continue;
}
int h=b-t+1;
int res=w*h+dp[i][j];
ans=max(ans,res);
for(int x:{t-1,b+1}){
for(int nr=pre[x][r][1],nl;nr>=l;nr=pre[x][nl][1]){
nl=max(l-1,pre[x][nr][0]);
int p=nl>=l?x:i;
dp[p][nr]=max(dp[p][nr],res-(nr-nl)*h);
}
}
}
return ans;
}
Compilation message
soccer.cpp: In function 'int biggest_stadium(int, std::vector<std::vector<int> >)':
soccer.cpp:21:13: warning: unused variable 't' [-Wunused-variable]
21 | int t=0,b=n+1;
| ^
soccer.cpp:21:17: warning: unused variable 'b' [-Wunused-variable]
21 | int t=0,b=n+1;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 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 |
604 KB |
ok |
4 |
Correct |
0 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
3 ms |
2908 KB |
ok |
8 |
Correct |
24 ms |
19936 KB |
ok |
9 |
Correct |
344 ms |
156756 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 |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
1 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 |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
1 ms |
348 KB |
ok |
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 |
0 ms |
604 KB |
ok |
16 |
Correct |
0 ms |
604 KB |
ok |
17 |
Correct |
0 ms |
604 KB |
ok |
18 |
Correct |
0 ms |
600 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
0 ms |
604 KB |
ok |
21 |
Correct |
1 ms |
604 KB |
ok |
22 |
Correct |
1 ms |
604 KB |
ok |
23 |
Correct |
0 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
604 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
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 |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
604 KB |
ok |
18 |
Correct |
0 ms |
604 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
0 ms |
600 KB |
ok |
21 |
Correct |
0 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
604 KB |
ok |
24 |
Correct |
1 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
604 KB |
ok |
28 |
Correct |
0 ms |
604 KB |
ok |
29 |
Correct |
0 ms |
604 KB |
ok |
30 |
Correct |
1 ms |
1116 KB |
ok |
31 |
Correct |
1 ms |
1116 KB |
ok |
32 |
Correct |
1 ms |
1116 KB |
ok |
33 |
Correct |
1 ms |
860 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
856 KB |
ok |
36 |
Correct |
0 ms |
860 KB |
ok |
37 |
Correct |
0 ms |
860 KB |
ok |
38 |
Correct |
1 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
0 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
1116 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
604 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
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 |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
604 KB |
ok |
18 |
Correct |
0 ms |
604 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
0 ms |
600 KB |
ok |
21 |
Correct |
0 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
604 KB |
ok |
24 |
Correct |
1 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
604 KB |
ok |
28 |
Correct |
0 ms |
604 KB |
ok |
29 |
Correct |
0 ms |
604 KB |
ok |
30 |
Correct |
1 ms |
1116 KB |
ok |
31 |
Correct |
1 ms |
1116 KB |
ok |
32 |
Correct |
1 ms |
1116 KB |
ok |
33 |
Correct |
1 ms |
860 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
856 KB |
ok |
36 |
Correct |
0 ms |
860 KB |
ok |
37 |
Correct |
0 ms |
860 KB |
ok |
38 |
Correct |
1 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
0 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
1116 KB |
ok |
42 |
Correct |
29 ms |
20488 KB |
ok |
43 |
Correct |
26 ms |
20172 KB |
ok |
44 |
Correct |
24 ms |
20940 KB |
ok |
45 |
Correct |
24 ms |
20820 KB |
ok |
46 |
Correct |
24 ms |
20824 KB |
ok |
47 |
Correct |
23 ms |
20316 KB |
ok |
48 |
Correct |
17 ms |
18008 KB |
ok |
49 |
Correct |
20 ms |
17920 KB |
ok |
50 |
Correct |
18 ms |
18340 KB |
ok |
51 |
Correct |
22 ms |
20604 KB |
ok |
52 |
Correct |
16 ms |
16728 KB |
ok |
53 |
Correct |
16 ms |
15964 KB |
ok |
54 |
Correct |
16 ms |
16860 KB |
ok |
55 |
Correct |
20 ms |
17244 KB |
ok |
56 |
Correct |
18 ms |
17496 KB |
ok |
57 |
Correct |
24 ms |
20828 KB |
ok |
58 |
Correct |
28 ms |
20736 KB |
ok |
59 |
Correct |
23 ms |
20828 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
604 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
3 ms |
2908 KB |
ok |
9 |
Correct |
24 ms |
19936 KB |
ok |
10 |
Correct |
344 ms |
156756 KB |
ok |
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 |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
0 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
600 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
604 KB |
ok |
28 |
Correct |
1 ms |
604 KB |
ok |
29 |
Correct |
1 ms |
604 KB |
ok |
30 |
Correct |
0 ms |
604 KB |
ok |
31 |
Correct |
0 ms |
604 KB |
ok |
32 |
Correct |
0 ms |
604 KB |
ok |
33 |
Correct |
0 ms |
604 KB |
ok |
34 |
Correct |
0 ms |
604 KB |
ok |
35 |
Correct |
1 ms |
1116 KB |
ok |
36 |
Correct |
1 ms |
1116 KB |
ok |
37 |
Correct |
1 ms |
1116 KB |
ok |
38 |
Correct |
1 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
1 ms |
856 KB |
ok |
41 |
Correct |
0 ms |
860 KB |
ok |
42 |
Correct |
0 ms |
860 KB |
ok |
43 |
Correct |
1 ms |
860 KB |
ok |
44 |
Correct |
1 ms |
860 KB |
ok |
45 |
Correct |
0 ms |
860 KB |
ok |
46 |
Correct |
1 ms |
1116 KB |
ok |
47 |
Correct |
29 ms |
20488 KB |
ok |
48 |
Correct |
26 ms |
20172 KB |
ok |
49 |
Correct |
24 ms |
20940 KB |
ok |
50 |
Correct |
24 ms |
20820 KB |
ok |
51 |
Correct |
24 ms |
20824 KB |
ok |
52 |
Correct |
23 ms |
20316 KB |
ok |
53 |
Correct |
17 ms |
18008 KB |
ok |
54 |
Correct |
20 ms |
17920 KB |
ok |
55 |
Correct |
18 ms |
18340 KB |
ok |
56 |
Correct |
22 ms |
20604 KB |
ok |
57 |
Correct |
16 ms |
16728 KB |
ok |
58 |
Correct |
16 ms |
15964 KB |
ok |
59 |
Correct |
16 ms |
16860 KB |
ok |
60 |
Correct |
20 ms |
17244 KB |
ok |
61 |
Correct |
18 ms |
17496 KB |
ok |
62 |
Correct |
24 ms |
20828 KB |
ok |
63 |
Correct |
28 ms |
20736 KB |
ok |
64 |
Correct |
23 ms |
20828 KB |
ok |
65 |
Correct |
428 ms |
158220 KB |
ok |
66 |
Correct |
295 ms |
136624 KB |
ok |
67 |
Correct |
244 ms |
128956 KB |
ok |
68 |
Correct |
315 ms |
166480 KB |
ok |
69 |
Correct |
345 ms |
161268 KB |
ok |
70 |
Correct |
387 ms |
160940 KB |
ok |
71 |
Correct |
360 ms |
165712 KB |
ok |
72 |
Correct |
347 ms |
157268 KB |
ok |
73 |
Correct |
282 ms |
137556 KB |
ok |
74 |
Correct |
272 ms |
137808 KB |
ok |
75 |
Correct |
287 ms |
137296 KB |
ok |
76 |
Correct |
300 ms |
146084 KB |
ok |
77 |
Correct |
286 ms |
146092 KB |
ok |
78 |
Correct |
361 ms |
164260 KB |
ok |
79 |
Correct |
233 ms |
128188 KB |
ok |
80 |
Correct |
229 ms |
127968 KB |
ok |
81 |
Correct |
252 ms |
130396 KB |
ok |
82 |
Correct |
278 ms |
135164 KB |
ok |
83 |
Correct |
291 ms |
133476 KB |
ok |
84 |
Correct |
245 ms |
117580 KB |
ok |
85 |
Correct |
214 ms |
114512 KB |
ok |
86 |
Correct |
230 ms |
120164 KB |
ok |
87 |
Correct |
247 ms |
120920 KB |
ok |
88 |
Correct |
254 ms |
130132 KB |
ok |
89 |
Correct |
324 ms |
144728 KB |
ok |
90 |
Correct |
280 ms |
137296 KB |
ok |
91 |
Correct |
291 ms |
146768 KB |
ok |
92 |
Correct |
259 ms |
130356 KB |
ok |
93 |
Correct |
248 ms |
130496 KB |
ok |
94 |
Correct |
231 ms |
128832 KB |
ok |
95 |
Correct |
233 ms |
128852 KB |
ok |
96 |
Correct |
235 ms |
127948 KB |
ok |
97 |
Correct |
212 ms |
127052 KB |
ok |
98 |
Correct |
211 ms |
119632 KB |
ok |
99 |
Correct |
353 ms |
158676 KB |
ok |
100 |
Correct |
346 ms |
165968 KB |
ok |
101 |
Correct |
352 ms |
165972 KB |
ok |
102 |
Correct |
352 ms |
165972 KB |
ok |
103 |
Correct |
348 ms |
166484 KB |
ok |
104 |
Correct |
374 ms |
167504 KB |
ok |
105 |
Correct |
342 ms |
166992 KB |
ok |
106 |
Correct |
409 ms |
166480 KB |
ok |
107 |
Correct |
348 ms |
167504 KB |
ok |
108 |
Correct |
263 ms |
157068 KB |
ok |
109 |
Correct |
284 ms |
158088 KB |
ok |