#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);
if(t>1){
for(int nr=pre[t-1][r][1],nl;nr>=l;nr=pre[t-1][nl][1]){
nl=max(l-1,pre[t-1][nr][0]);
int p=nl>=l?t-1:i;
dp[p][nr]=max(dp[p][nr],res-(nr-nl)*h);
}
}
if(b<n){
for(int nr=pre[b+1][r][1],nl;nr>=l;nr=pre[b+1][nl][1]){
nl=max(l-1,pre[b+1][nr][0]);
int p=nl>=l?b+1: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 |
600 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 |
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 |
1 ms |
2908 KB |
ok |
8 |
Correct |
22 ms |
19928 KB |
ok |
9 |
Correct |
321 ms |
156756 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 |
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 |
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 |
600 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
344 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 |
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 |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
1 ms |
604 KB |
ok |
16 |
Correct |
0 ms |
600 KB |
ok |
17 |
Correct |
0 ms |
604 KB |
ok |
18 |
Correct |
1 ms |
604 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
0 ms |
604 KB |
ok |
21 |
Correct |
1 ms |
600 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
0 ms |
604 KB |
ok |
24 |
Correct |
1 ms |
604 KB |
ok |
25 |
Correct |
1 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
604 KB |
ok |
6 |
Correct |
0 ms |
344 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 |
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 |
604 KB |
ok |
18 |
Correct |
0 ms |
600 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
1 ms |
604 KB |
ok |
21 |
Correct |
0 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
600 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
1 ms |
604 KB |
ok |
27 |
Correct |
1 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 |
0 ms |
1116 KB |
ok |
33 |
Correct |
1 ms |
860 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
860 KB |
ok |
36 |
Correct |
0 ms |
860 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
0 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
1 ms |
1116 KB |
ok |
41 |
Correct |
1 ms |
1112 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
604 KB |
ok |
6 |
Correct |
0 ms |
344 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 |
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 |
604 KB |
ok |
18 |
Correct |
0 ms |
600 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
1 ms |
604 KB |
ok |
21 |
Correct |
0 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
600 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
1 ms |
604 KB |
ok |
27 |
Correct |
1 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 |
0 ms |
1116 KB |
ok |
33 |
Correct |
1 ms |
860 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
860 KB |
ok |
36 |
Correct |
0 ms |
860 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
0 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
1 ms |
1116 KB |
ok |
41 |
Correct |
1 ms |
1112 KB |
ok |
42 |
Correct |
23 ms |
20364 KB |
ok |
43 |
Correct |
24 ms |
20172 KB |
ok |
44 |
Correct |
20 ms |
20828 KB |
ok |
45 |
Correct |
24 ms |
20828 KB |
ok |
46 |
Correct |
24 ms |
20828 KB |
ok |
47 |
Correct |
22 ms |
20312 KB |
ok |
48 |
Correct |
20 ms |
18012 KB |
ok |
49 |
Correct |
20 ms |
17880 KB |
ok |
50 |
Correct |
21 ms |
18264 KB |
ok |
51 |
Correct |
24 ms |
20684 KB |
ok |
52 |
Correct |
18 ms |
16592 KB |
ok |
53 |
Correct |
17 ms |
15964 KB |
ok |
54 |
Correct |
18 ms |
16732 KB |
ok |
55 |
Correct |
19 ms |
17244 KB |
ok |
56 |
Correct |
20 ms |
17496 KB |
ok |
57 |
Correct |
24 ms |
20828 KB |
ok |
58 |
Correct |
26 ms |
20644 KB |
ok |
59 |
Correct |
24 ms |
20828 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 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 |
1 ms |
2908 KB |
ok |
9 |
Correct |
22 ms |
19928 KB |
ok |
10 |
Correct |
321 ms |
156756 KB |
ok |
11 |
Correct |
0 ms |
344 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 |
0 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 |
1 ms |
604 KB |
ok |
23 |
Correct |
0 ms |
600 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
1 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
604 KB |
ok |
28 |
Correct |
1 ms |
600 KB |
ok |
29 |
Correct |
0 ms |
604 KB |
ok |
30 |
Correct |
0 ms |
604 KB |
ok |
31 |
Correct |
1 ms |
604 KB |
ok |
32 |
Correct |
1 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 |
0 ms |
1116 KB |
ok |
38 |
Correct |
1 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
1 ms |
860 KB |
ok |
41 |
Correct |
0 ms |
860 KB |
ok |
42 |
Correct |
1 ms |
860 KB |
ok |
43 |
Correct |
0 ms |
860 KB |
ok |
44 |
Correct |
1 ms |
860 KB |
ok |
45 |
Correct |
1 ms |
1116 KB |
ok |
46 |
Correct |
1 ms |
1112 KB |
ok |
47 |
Correct |
23 ms |
20364 KB |
ok |
48 |
Correct |
24 ms |
20172 KB |
ok |
49 |
Correct |
20 ms |
20828 KB |
ok |
50 |
Correct |
24 ms |
20828 KB |
ok |
51 |
Correct |
24 ms |
20828 KB |
ok |
52 |
Correct |
22 ms |
20312 KB |
ok |
53 |
Correct |
20 ms |
18012 KB |
ok |
54 |
Correct |
20 ms |
17880 KB |
ok |
55 |
Correct |
21 ms |
18264 KB |
ok |
56 |
Correct |
24 ms |
20684 KB |
ok |
57 |
Correct |
18 ms |
16592 KB |
ok |
58 |
Correct |
17 ms |
15964 KB |
ok |
59 |
Correct |
18 ms |
16732 KB |
ok |
60 |
Correct |
19 ms |
17244 KB |
ok |
61 |
Correct |
20 ms |
17496 KB |
ok |
62 |
Correct |
24 ms |
20828 KB |
ok |
63 |
Correct |
26 ms |
20644 KB |
ok |
64 |
Correct |
24 ms |
20828 KB |
ok |
65 |
Correct |
455 ms |
158304 KB |
ok |
66 |
Correct |
330 ms |
136624 KB |
ok |
67 |
Correct |
265 ms |
128964 KB |
ok |
68 |
Correct |
373 ms |
166496 KB |
ok |
69 |
Correct |
375 ms |
161276 KB |
ok |
70 |
Correct |
413 ms |
160944 KB |
ok |
71 |
Correct |
425 ms |
165688 KB |
ok |
72 |
Correct |
355 ms |
157268 KB |
ok |
73 |
Correct |
303 ms |
137552 KB |
ok |
74 |
Correct |
273 ms |
137808 KB |
ok |
75 |
Correct |
274 ms |
137296 KB |
ok |
76 |
Correct |
312 ms |
146344 KB |
ok |
77 |
Correct |
304 ms |
146088 KB |
ok |
78 |
Correct |
328 ms |
164264 KB |
ok |
79 |
Correct |
266 ms |
128192 KB |
ok |
80 |
Correct |
289 ms |
127948 KB |
ok |
81 |
Correct |
242 ms |
129984 KB |
ok |
82 |
Correct |
286 ms |
135160 KB |
ok |
83 |
Correct |
290 ms |
133248 KB |
ok |
84 |
Correct |
256 ms |
117580 KB |
ok |
85 |
Correct |
231 ms |
114512 KB |
ok |
86 |
Correct |
231 ms |
120144 KB |
ok |
87 |
Correct |
245 ms |
120916 KB |
ok |
88 |
Correct |
288 ms |
130128 KB |
ok |
89 |
Correct |
330 ms |
144720 KB |
ok |
90 |
Correct |
315 ms |
137296 KB |
ok |
91 |
Correct |
318 ms |
146772 KB |
ok |
92 |
Correct |
314 ms |
130352 KB |
ok |
93 |
Correct |
260 ms |
130492 KB |
ok |
94 |
Correct |
249 ms |
129084 KB |
ok |
95 |
Correct |
248 ms |
128568 KB |
ok |
96 |
Correct |
252 ms |
127952 KB |
ok |
97 |
Correct |
277 ms |
127076 KB |
ok |
98 |
Correct |
230 ms |
119632 KB |
ok |
99 |
Correct |
337 ms |
158700 KB |
ok |
100 |
Correct |
360 ms |
165972 KB |
ok |
101 |
Correct |
352 ms |
165968 KB |
ok |
102 |
Correct |
335 ms |
166224 KB |
ok |
103 |
Correct |
369 ms |
166224 KB |
ok |
104 |
Correct |
401 ms |
167508 KB |
ok |
105 |
Correct |
389 ms |
166992 KB |
ok |
106 |
Correct |
354 ms |
166480 KB |
ok |
107 |
Correct |
380 ms |
167248 KB |
ok |
108 |
Correct |
304 ms |
157084 KB |
ok |
109 |
Correct |
330 ms |
158096 KB |
ok |