#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]?min(i,i>1?top[i-1][j]:n+1):n+1;
for(int i=n;i>=1;i--)for(int j=1;j<=n;j++)bot[i][j]=a[i][j]?max(i,bot[i+1][j]):0;
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];
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:20:13: warning: unused variable 't' [-Wunused-variable]
20 | int t=0,b=n+1;
| ^
soccer.cpp:20:17: warning: unused variable 'b' [-Wunused-variable]
20 | int t=0,b=n+1;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
492 KB |
ok |
4 |
Correct |
1 ms |
604 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Correct |
3 ms |
2812 KB |
ok |
8 |
Correct |
24 ms |
19804 KB |
ok |
9 |
Correct |
396 ms |
158292 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
396 KB |
ok |
11 |
Correct |
0 ms |
360 KB |
ok |
12 |
Correct |
0 ms |
500 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 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 |
0 ms |
344 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 |
396 KB |
ok |
12 |
Correct |
0 ms |
360 KB |
ok |
13 |
Correct |
0 ms |
500 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
604 KB |
ok |
16 |
Correct |
1 ms |
604 KB |
ok |
17 |
Correct |
0 ms |
500 KB |
ok |
18 |
Correct |
1 ms |
604 KB |
ok |
19 |
Correct |
0 ms |
604 KB |
ok |
20 |
Correct |
0 ms |
496 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 |
0 ms |
496 KB |
ok |
25 |
Correct |
0 ms |
504 KB |
ok |
26 |
Correct |
1 ms |
608 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
492 KB |
ok |
5 |
Correct |
1 ms |
604 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
344 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
1 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
396 KB |
ok |
14 |
Correct |
0 ms |
360 KB |
ok |
15 |
Correct |
0 ms |
500 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
604 KB |
ok |
18 |
Correct |
1 ms |
604 KB |
ok |
19 |
Correct |
0 ms |
500 KB |
ok |
20 |
Correct |
1 ms |
604 KB |
ok |
21 |
Correct |
0 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
496 KB |
ok |
23 |
Correct |
0 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
1 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
496 KB |
ok |
27 |
Correct |
0 ms |
504 KB |
ok |
28 |
Correct |
1 ms |
608 KB |
ok |
29 |
Correct |
0 ms |
608 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 |
1004 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
860 KB |
ok |
36 |
Correct |
1 ms |
860 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
1 ms |
864 KB |
ok |
39 |
Correct |
1 ms |
1052 KB |
ok |
40 |
Correct |
1 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
1016 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
492 KB |
ok |
5 |
Correct |
1 ms |
604 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
344 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
1 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
396 KB |
ok |
14 |
Correct |
0 ms |
360 KB |
ok |
15 |
Correct |
0 ms |
500 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
604 KB |
ok |
18 |
Correct |
1 ms |
604 KB |
ok |
19 |
Correct |
0 ms |
500 KB |
ok |
20 |
Correct |
1 ms |
604 KB |
ok |
21 |
Correct |
0 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
496 KB |
ok |
23 |
Correct |
0 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
1 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
496 KB |
ok |
27 |
Correct |
0 ms |
504 KB |
ok |
28 |
Correct |
1 ms |
608 KB |
ok |
29 |
Correct |
0 ms |
608 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 |
1004 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
860 KB |
ok |
36 |
Correct |
1 ms |
860 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
1 ms |
864 KB |
ok |
39 |
Correct |
1 ms |
1052 KB |
ok |
40 |
Correct |
1 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
1016 KB |
ok |
42 |
Correct |
37 ms |
20812 KB |
ok |
43 |
Correct |
32 ms |
20756 KB |
ok |
44 |
Correct |
42 ms |
21436 KB |
ok |
45 |
Correct |
41 ms |
21268 KB |
ok |
46 |
Correct |
33 ms |
21240 KB |
ok |
47 |
Correct |
32 ms |
20400 KB |
ok |
48 |
Correct |
25 ms |
18872 KB |
ok |
49 |
Correct |
23 ms |
18864 KB |
ok |
50 |
Correct |
193 ms |
18772 KB |
ok |
51 |
Correct |
27 ms |
21200 KB |
ok |
52 |
Correct |
19 ms |
17252 KB |
ok |
53 |
Correct |
19 ms |
16472 KB |
ok |
54 |
Correct |
19 ms |
17244 KB |
ok |
55 |
Correct |
20 ms |
17864 KB |
ok |
56 |
Correct |
20 ms |
18004 KB |
ok |
57 |
Correct |
35 ms |
21076 KB |
ok |
58 |
Correct |
25 ms |
21332 KB |
ok |
59 |
Correct |
30 ms |
21328 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
604 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
492 KB |
ok |
5 |
Correct |
1 ms |
604 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
344 KB |
ok |
8 |
Correct |
3 ms |
2812 KB |
ok |
9 |
Correct |
24 ms |
19804 KB |
ok |
10 |
Correct |
396 ms |
158292 KB |
ok |
11 |
Correct |
1 ms |
344 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
344 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
1 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
396 KB |
ok |
19 |
Correct |
0 ms |
360 KB |
ok |
20 |
Correct |
0 ms |
500 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
500 KB |
ok |
25 |
Correct |
1 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
496 KB |
ok |
28 |
Correct |
0 ms |
604 KB |
ok |
29 |
Correct |
0 ms |
604 KB |
ok |
30 |
Correct |
1 ms |
604 KB |
ok |
31 |
Correct |
0 ms |
496 KB |
ok |
32 |
Correct |
0 ms |
504 KB |
ok |
33 |
Correct |
1 ms |
608 KB |
ok |
34 |
Correct |
0 ms |
608 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 |
1004 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
1 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
860 KB |
ok |
42 |
Correct |
1 ms |
860 KB |
ok |
43 |
Correct |
1 ms |
864 KB |
ok |
44 |
Correct |
1 ms |
1052 KB |
ok |
45 |
Correct |
1 ms |
860 KB |
ok |
46 |
Correct |
1 ms |
1016 KB |
ok |
47 |
Correct |
37 ms |
20812 KB |
ok |
48 |
Correct |
32 ms |
20756 KB |
ok |
49 |
Correct |
42 ms |
21436 KB |
ok |
50 |
Correct |
41 ms |
21268 KB |
ok |
51 |
Correct |
33 ms |
21240 KB |
ok |
52 |
Correct |
32 ms |
20400 KB |
ok |
53 |
Correct |
25 ms |
18872 KB |
ok |
54 |
Correct |
23 ms |
18864 KB |
ok |
55 |
Correct |
193 ms |
18772 KB |
ok |
56 |
Correct |
27 ms |
21200 KB |
ok |
57 |
Correct |
19 ms |
17252 KB |
ok |
58 |
Correct |
19 ms |
16472 KB |
ok |
59 |
Correct |
19 ms |
17244 KB |
ok |
60 |
Correct |
20 ms |
17864 KB |
ok |
61 |
Correct |
20 ms |
18004 KB |
ok |
62 |
Correct |
35 ms |
21076 KB |
ok |
63 |
Correct |
25 ms |
21332 KB |
ok |
64 |
Correct |
30 ms |
21328 KB |
ok |
65 |
Correct |
681 ms |
166124 KB |
ok |
66 |
Correct |
350 ms |
144304 KB |
ok |
67 |
Correct |
272 ms |
136900 KB |
ok |
68 |
Correct |
605 ms |
174280 KB |
ok |
69 |
Correct |
711 ms |
168960 KB |
ok |
70 |
Correct |
884 ms |
168872 KB |
ok |
71 |
Correct |
654 ms |
173652 KB |
ok |
72 |
Correct |
497 ms |
164948 KB |
ok |
73 |
Correct |
353 ms |
149328 KB |
ok |
74 |
Correct |
368 ms |
149824 KB |
ok |
75 |
Correct |
426 ms |
149068 KB |
ok |
76 |
Execution timed out |
4550 ms |
154032 KB |
Time limit exceeded |
77 |
Halted |
0 ms |
0 KB |
- |