#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;
#ifndef WAIMAI
#include "soccer.h"
#else
#include "grader.cpp"
#endif
#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif
#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second
const int SIZE = 2005;
int n, ans;
bool a[SIZE][SIZE];
vector<pair<int, int>> p[SIZE];
int U[SIZE][SIZE], L[SIZE][SIZE], R[SIZE][SIZE], dp[SIZE][SIZE];
int biggest_stadium(int N, vector<vector<int>> F) {
n = N, ans = 0;
FOR (i, 1, n) p[i].clear();
FOR (i, 1, n) FOR (j, 1, n) a[i][j] = F[i - 1][j - 1], dp[i][j] = 0;
FOR (i, 1, n) {
FOR (j, 1, n) {
U[i][j] = (a[i][j] ? i : U[i - 1][j]);
L[i][j] = (a[i][j] ? j : L[i][j - 1]);
if (U[i][j] < i) p[i - U[i][j]].pb(i, j);
}
R[i][n + 1] = n + 1;
for (int j = n; j >= 1; j--) R[i][j] = (a[i][j] ? j : R[i][j + 1]);
}
FOR (ulen, 1, n) for (auto [x, y] : p[ulen]) {
if (ulen > 1) {
L[x][y] = max(L[x][y], L[x - 1][y]);
R[x][y] = min(R[x][y], R[x - 1][y]);
}
dp[x][y] = dp[x- 1][y] + (R[x][y] - L[x][y] - 1);
if (L[x][y] >= 1) dp[x][y] = max(dp[x][y], dp[x][L[x][y]] + (U[x][L[x][y]] - U[x][y]) * (R[x][y] - L[x][y] - 1));
if (R[x][y] <= n) dp[x][y] = max(dp[x][y], dp[x][R[x][y]] + (U[x][R[x][y]] - U[x][y]) * (R[x][y] - L[x][y] - 1));
ans = max(ans, dp[x][y]);
}
return ans;
}
/*
in1
5
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
out1
20
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
1 ms |
4444 KB |
ok |
3 |
Correct |
1 ms |
8540 KB |
ok |
4 |
Correct |
1 ms |
4444 KB |
ok |
5 |
Correct |
1 ms |
4444 KB |
ok |
6 |
Correct |
1 ms |
4444 KB |
ok |
7 |
Correct |
2 ms |
9308 KB |
ok |
8 |
Correct |
35 ms |
26972 KB |
ok |
9 |
Correct |
253 ms |
138584 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
1 ms |
4444 KB |
ok |
3 |
Correct |
1 ms |
4444 KB |
ok |
4 |
Correct |
1 ms |
4444 KB |
ok |
5 |
Correct |
1 ms |
4444 KB |
ok |
6 |
Correct |
1 ms |
8540 KB |
ok |
7 |
Correct |
1 ms |
4548 KB |
ok |
8 |
Correct |
1 ms |
4444 KB |
ok |
9 |
Correct |
1 ms |
4444 KB |
ok |
10 |
Correct |
1 ms |
4444 KB |
ok |
11 |
Correct |
1 ms |
4444 KB |
ok |
12 |
Correct |
1 ms |
4444 KB |
ok |
13 |
Correct |
1 ms |
8540 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
1 ms |
4444 KB |
ok |
3 |
Correct |
1 ms |
4444 KB |
ok |
4 |
Correct |
1 ms |
4444 KB |
ok |
5 |
Correct |
1 ms |
4444 KB |
ok |
6 |
Correct |
1 ms |
4444 KB |
ok |
7 |
Correct |
1 ms |
8540 KB |
ok |
8 |
Correct |
1 ms |
4548 KB |
ok |
9 |
Correct |
1 ms |
4444 KB |
ok |
10 |
Correct |
1 ms |
4444 KB |
ok |
11 |
Correct |
1 ms |
4444 KB |
ok |
12 |
Correct |
1 ms |
4444 KB |
ok |
13 |
Correct |
1 ms |
4444 KB |
ok |
14 |
Correct |
1 ms |
8540 KB |
ok |
15 |
Correct |
1 ms |
4440 KB |
ok |
16 |
Correct |
1 ms |
4444 KB |
ok |
17 |
Correct |
1 ms |
4444 KB |
ok |
18 |
Correct |
1 ms |
4444 KB |
ok |
19 |
Correct |
1 ms |
4440 KB |
ok |
20 |
Correct |
1 ms |
8536 KB |
ok |
21 |
Correct |
2 ms |
8540 KB |
ok |
22 |
Correct |
2 ms |
8540 KB |
ok |
23 |
Correct |
1 ms |
8540 KB |
ok |
24 |
Correct |
1 ms |
8536 KB |
ok |
25 |
Correct |
1 ms |
8536 KB |
ok |
26 |
Correct |
1 ms |
4544 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
1 ms |
4444 KB |
ok |
3 |
Correct |
1 ms |
4444 KB |
ok |
4 |
Correct |
1 ms |
8540 KB |
ok |
5 |
Correct |
1 ms |
4444 KB |
ok |
6 |
Correct |
1 ms |
4444 KB |
ok |
7 |
Correct |
1 ms |
4444 KB |
ok |
8 |
Correct |
1 ms |
4444 KB |
ok |
9 |
Correct |
1 ms |
8540 KB |
ok |
10 |
Correct |
1 ms |
4548 KB |
ok |
11 |
Correct |
1 ms |
4444 KB |
ok |
12 |
Correct |
1 ms |
4444 KB |
ok |
13 |
Correct |
1 ms |
4444 KB |
ok |
14 |
Correct |
1 ms |
4444 KB |
ok |
15 |
Correct |
1 ms |
4444 KB |
ok |
16 |
Correct |
1 ms |
8540 KB |
ok |
17 |
Correct |
1 ms |
4440 KB |
ok |
18 |
Correct |
1 ms |
4444 KB |
ok |
19 |
Correct |
1 ms |
4444 KB |
ok |
20 |
Correct |
1 ms |
4444 KB |
ok |
21 |
Correct |
1 ms |
4440 KB |
ok |
22 |
Correct |
1 ms |
8536 KB |
ok |
23 |
Correct |
2 ms |
8540 KB |
ok |
24 |
Correct |
2 ms |
8540 KB |
ok |
25 |
Correct |
1 ms |
8540 KB |
ok |
26 |
Correct |
1 ms |
8536 KB |
ok |
27 |
Correct |
1 ms |
8536 KB |
ok |
28 |
Correct |
1 ms |
4544 KB |
ok |
29 |
Correct |
1 ms |
8536 KB |
ok |
30 |
Correct |
2 ms |
8796 KB |
ok |
31 |
Correct |
1 ms |
8796 KB |
ok |
32 |
Correct |
2 ms |
8892 KB |
ok |
33 |
Correct |
2 ms |
12636 KB |
ok |
34 |
Correct |
2 ms |
12636 KB |
ok |
35 |
Correct |
2 ms |
12636 KB |
ok |
36 |
Correct |
2 ms |
12636 KB |
ok |
37 |
Correct |
2 ms |
12636 KB |
ok |
38 |
Correct |
1 ms |
12636 KB |
ok |
39 |
Correct |
2 ms |
12636 KB |
ok |
40 |
Correct |
1 ms |
8796 KB |
ok |
41 |
Correct |
1 ms |
8796 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
1 ms |
4444 KB |
ok |
3 |
Correct |
1 ms |
4444 KB |
ok |
4 |
Correct |
1 ms |
8540 KB |
ok |
5 |
Correct |
1 ms |
4444 KB |
ok |
6 |
Correct |
1 ms |
4444 KB |
ok |
7 |
Correct |
1 ms |
4444 KB |
ok |
8 |
Correct |
1 ms |
4444 KB |
ok |
9 |
Correct |
1 ms |
8540 KB |
ok |
10 |
Correct |
1 ms |
4548 KB |
ok |
11 |
Correct |
1 ms |
4444 KB |
ok |
12 |
Correct |
1 ms |
4444 KB |
ok |
13 |
Correct |
1 ms |
4444 KB |
ok |
14 |
Correct |
1 ms |
4444 KB |
ok |
15 |
Correct |
1 ms |
4444 KB |
ok |
16 |
Correct |
1 ms |
8540 KB |
ok |
17 |
Correct |
1 ms |
4440 KB |
ok |
18 |
Correct |
1 ms |
4444 KB |
ok |
19 |
Correct |
1 ms |
4444 KB |
ok |
20 |
Correct |
1 ms |
4444 KB |
ok |
21 |
Correct |
1 ms |
4440 KB |
ok |
22 |
Correct |
1 ms |
8536 KB |
ok |
23 |
Correct |
2 ms |
8540 KB |
ok |
24 |
Correct |
2 ms |
8540 KB |
ok |
25 |
Correct |
1 ms |
8540 KB |
ok |
26 |
Correct |
1 ms |
8536 KB |
ok |
27 |
Correct |
1 ms |
8536 KB |
ok |
28 |
Correct |
1 ms |
4544 KB |
ok |
29 |
Correct |
1 ms |
8536 KB |
ok |
30 |
Correct |
2 ms |
8796 KB |
ok |
31 |
Correct |
1 ms |
8796 KB |
ok |
32 |
Correct |
2 ms |
8892 KB |
ok |
33 |
Correct |
2 ms |
12636 KB |
ok |
34 |
Correct |
2 ms |
12636 KB |
ok |
35 |
Correct |
2 ms |
12636 KB |
ok |
36 |
Correct |
2 ms |
12636 KB |
ok |
37 |
Correct |
2 ms |
12636 KB |
ok |
38 |
Correct |
1 ms |
12636 KB |
ok |
39 |
Correct |
2 ms |
12636 KB |
ok |
40 |
Correct |
1 ms |
8796 KB |
ok |
41 |
Correct |
1 ms |
8796 KB |
ok |
42 |
Correct |
20 ms |
27192 KB |
ok |
43 |
Correct |
19 ms |
26884 KB |
ok |
44 |
Correct |
29 ms |
27472 KB |
ok |
45 |
Correct |
20 ms |
27676 KB |
ok |
46 |
Correct |
27 ms |
27480 KB |
ok |
47 |
Correct |
19 ms |
27228 KB |
ok |
48 |
Correct |
19 ms |
30872 KB |
ok |
49 |
Correct |
17 ms |
31064 KB |
ok |
50 |
Correct |
18 ms |
29452 KB |
ok |
51 |
Correct |
19 ms |
32088 KB |
ok |
52 |
Correct |
17 ms |
29980 KB |
ok |
53 |
Correct |
15 ms |
29788 KB |
ok |
54 |
Correct |
18 ms |
30040 KB |
ok |
55 |
Correct |
29 ms |
30292 KB |
ok |
56 |
Correct |
15 ms |
27740 KB |
ok |
57 |
Correct |
33 ms |
27728 KB |
ok |
58 |
Correct |
33 ms |
27728 KB |
ok |
59 |
Correct |
20 ms |
27800 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
1 ms |
4444 KB |
ok |
3 |
Correct |
1 ms |
4444 KB |
ok |
4 |
Correct |
1 ms |
8540 KB |
ok |
5 |
Correct |
1 ms |
4444 KB |
ok |
6 |
Correct |
1 ms |
4444 KB |
ok |
7 |
Correct |
1 ms |
4444 KB |
ok |
8 |
Correct |
2 ms |
9308 KB |
ok |
9 |
Correct |
35 ms |
26972 KB |
ok |
10 |
Correct |
253 ms |
138584 KB |
ok |
11 |
Correct |
1 ms |
4444 KB |
ok |
12 |
Correct |
1 ms |
4444 KB |
ok |
13 |
Correct |
1 ms |
4444 KB |
ok |
14 |
Correct |
1 ms |
8540 KB |
ok |
15 |
Correct |
1 ms |
4548 KB |
ok |
16 |
Correct |
1 ms |
4444 KB |
ok |
17 |
Correct |
1 ms |
4444 KB |
ok |
18 |
Correct |
1 ms |
4444 KB |
ok |
19 |
Correct |
1 ms |
4444 KB |
ok |
20 |
Correct |
1 ms |
4444 KB |
ok |
21 |
Correct |
1 ms |
8540 KB |
ok |
22 |
Correct |
1 ms |
4440 KB |
ok |
23 |
Correct |
1 ms |
4444 KB |
ok |
24 |
Correct |
1 ms |
4444 KB |
ok |
25 |
Correct |
1 ms |
4444 KB |
ok |
26 |
Correct |
1 ms |
4440 KB |
ok |
27 |
Correct |
1 ms |
8536 KB |
ok |
28 |
Correct |
2 ms |
8540 KB |
ok |
29 |
Correct |
2 ms |
8540 KB |
ok |
30 |
Correct |
1 ms |
8540 KB |
ok |
31 |
Correct |
1 ms |
8536 KB |
ok |
32 |
Correct |
1 ms |
8536 KB |
ok |
33 |
Correct |
1 ms |
4544 KB |
ok |
34 |
Correct |
1 ms |
8536 KB |
ok |
35 |
Correct |
2 ms |
8796 KB |
ok |
36 |
Correct |
1 ms |
8796 KB |
ok |
37 |
Correct |
2 ms |
8892 KB |
ok |
38 |
Correct |
2 ms |
12636 KB |
ok |
39 |
Correct |
2 ms |
12636 KB |
ok |
40 |
Correct |
2 ms |
12636 KB |
ok |
41 |
Correct |
2 ms |
12636 KB |
ok |
42 |
Correct |
2 ms |
12636 KB |
ok |
43 |
Correct |
1 ms |
12636 KB |
ok |
44 |
Correct |
2 ms |
12636 KB |
ok |
45 |
Correct |
1 ms |
8796 KB |
ok |
46 |
Correct |
1 ms |
8796 KB |
ok |
47 |
Correct |
20 ms |
27192 KB |
ok |
48 |
Correct |
19 ms |
26884 KB |
ok |
49 |
Correct |
29 ms |
27472 KB |
ok |
50 |
Correct |
20 ms |
27676 KB |
ok |
51 |
Correct |
27 ms |
27480 KB |
ok |
52 |
Correct |
19 ms |
27228 KB |
ok |
53 |
Correct |
19 ms |
30872 KB |
ok |
54 |
Correct |
17 ms |
31064 KB |
ok |
55 |
Correct |
18 ms |
29452 KB |
ok |
56 |
Correct |
19 ms |
32088 KB |
ok |
57 |
Correct |
17 ms |
29980 KB |
ok |
58 |
Correct |
15 ms |
29788 KB |
ok |
59 |
Correct |
18 ms |
30040 KB |
ok |
60 |
Correct |
29 ms |
30292 KB |
ok |
61 |
Correct |
15 ms |
27740 KB |
ok |
62 |
Correct |
33 ms |
27728 KB |
ok |
63 |
Correct |
33 ms |
27728 KB |
ok |
64 |
Correct |
20 ms |
27800 KB |
ok |
65 |
Correct |
316 ms |
140448 KB |
ok |
66 |
Correct |
284 ms |
116912 KB |
ok |
67 |
Correct |
237 ms |
110012 KB |
ok |
68 |
Correct |
380 ms |
145744 KB |
ok |
69 |
Correct |
393 ms |
142136 KB |
ok |
70 |
Correct |
384 ms |
141504 KB |
ok |
71 |
Correct |
325 ms |
144724 KB |
ok |
72 |
Correct |
270 ms |
138576 KB |
ok |
73 |
Correct |
258 ms |
126800 KB |
ok |
74 |
Correct |
253 ms |
127004 KB |
ok |
75 |
Correct |
256 ms |
126756 KB |
ok |
76 |
Correct |
253 ms |
130492 KB |
ok |
77 |
Correct |
248 ms |
130488 KB |
ok |
78 |
Correct |
297 ms |
142956 KB |
ok |
79 |
Correct |
231 ms |
108564 KB |
ok |
80 |
Correct |
232 ms |
108484 KB |
ok |
81 |
Correct |
250 ms |
110760 KB |
ok |
82 |
Correct |
248 ms |
115568 KB |
ok |
83 |
Correct |
250 ms |
115792 KB |
ok |
84 |
Correct |
267 ms |
110676 KB |
ok |
85 |
Correct |
231 ms |
108980 KB |
ok |
86 |
Correct |
224 ms |
112208 KB |
ok |
87 |
Correct |
249 ms |
113232 KB |
ok |
88 |
Correct |
226 ms |
120404 KB |
ok |
89 |
Correct |
269 ms |
137556 KB |
ok |
90 |
Correct |
244 ms |
135508 KB |
ok |
91 |
Correct |
262 ms |
137556 KB |
ok |
92 |
Correct |
264 ms |
111112 KB |
ok |
93 |
Correct |
253 ms |
111812 KB |
ok |
94 |
Correct |
232 ms |
109252 KB |
ok |
95 |
Correct |
279 ms |
111040 KB |
ok |
96 |
Correct |
245 ms |
111132 KB |
ok |
97 |
Correct |
236 ms |
111372 KB |
ok |
98 |
Correct |
226 ms |
108224 KB |
ok |
99 |
Correct |
303 ms |
139216 KB |
ok |
100 |
Correct |
291 ms |
145188 KB |
ok |
101 |
Correct |
536 ms |
143956 KB |
ok |
102 |
Correct |
295 ms |
143960 KB |
ok |
103 |
Correct |
292 ms |
145620 KB |
ok |
104 |
Correct |
305 ms |
145448 KB |
ok |
105 |
Correct |
284 ms |
145956 KB |
ok |
106 |
Correct |
305 ms |
146848 KB |
ok |
107 |
Correct |
308 ms |
147648 KB |
ok |
108 |
Correct |
273 ms |
135540 KB |
ok |
109 |
Correct |
273 ms |
136388 KB |
ok |