#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = (int) 1e9;
const int N = 52;
int dp[N][N][N][N];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
bool check_all(int n, vector<vector<int>> a) {
vector<vector<bool>> was(n, vector<bool>(n));
function<void(int, int)> Dfs = [&](int x, int y) {
if (x < 0 || x >= n || y < 0 || y >= n || a[x][y] == 1 || was[x][y]) {
return;
}
was[x][y] = true;
for (int d = 0; d < 4; d++) {
Dfs(x + dx[d], y + dy[d]);
}
};
bool done = false;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (!done && a[i][j] == 0) {
Dfs(i, j);
done = true;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 0 && !was[i][j]) {
return false;
}
}
}
vector<pair<int, int>> seg;
for (int j = 0; j < n; j++) {
int cnt = 0;
for (int i = 0; i < n; i++) {
if (a[i][j] == 1) {
continue;
}
cnt += 1;
if (cnt == 2) {
return false;
}
int ptr = i;
while (ptr + 1 < n && a[ptr + 1][j] == 0) {
ptr += 1;
}
seg.emplace_back(i, ptr);
i = ptr;
}
}
int sz = (int) seg.size();
int mx = 0;
for (int i = 1; i < sz; i++) {
if (seg[i].second - seg[i].first > seg[mx].second - seg[mx].first) {
mx = i;
}
}
int l = mx, r = mx, lst = mx;
while (l != 0 || r != sz - 1) {
if (l == 0 || (r + 1 < sz && seg[r + 1].second - seg[r + 1].first > seg[l - 1].second - seg[l - 1].first)) {
if (!(seg[lst].first <= seg[r + 1].first && seg[r + 1].second <= seg[lst].second)) {
return false;
}
r += 1;
lst = r;
} else {
if (!(seg[lst].first <= seg[l - 1].first && seg[l - 1].second <= seg[lst].second)) {
return false;
}
l -= 1;
lst = l;
}
}
return true;
}
int biggest_stadium(int n, vector<vector<int>> a) {
if (check_all(n, a)) {
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (a[i][j] == 0) {
cnt += 1;
}
}
}
return cnt;
}
if (n > 50) {
return 0;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
dp[i][j][x][y] = -inf;
}
}
}
}
for (int r = 0; r < n; r++) {
for (int l = r; l >= 0; l--) {
if (l == r) {
for (int i = 0; i < n; i++) {
int cnt = 0;
for (int j = i; j < n; j++) {
cnt += 1;
if (a[l][j] == 1) {
break;
}
dp[l][r][i][j] = cnt;
}
}
continue;
}
{
// left
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (a[l][j] == 1) {
break;
}
for (int x = 0; x <= i; x++) {
for (int y = j; y < n; y++) {
dp[l][r][i][j] = max(dp[l][r][i][j], dp[l + 1][r][x][y] + (j - i + 1));
}
}
}
}
}
{
// right
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (a[r][j] == 1) {
break;
}
for (int x = 0; x <= i; x++) {
for (int y = j; y < n; y++) {
dp[l][r][i][j] = max(dp[l][r][i][j], dp[l][r - 1][x][y] + (j - i + 1));
}
}
}
}
}
}
}
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int x = 0; x < n; x++) {
for (int y = 0; y < n; y++) {
res = max(res, dp[i][j][x][y]);
}
}
}
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
2396 KB |
ok |
7 |
Partially correct |
2 ms |
1112 KB |
partial |
8 |
Partially correct |
35 ms |
22964 KB |
partial |
9 |
Partially correct |
603 ms |
361244 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
2392 KB |
ok |
4 |
Correct |
1 ms |
2396 KB |
ok |
5 |
Correct |
1 ms |
2392 KB |
ok |
6 |
Correct |
0 ms |
2396 KB |
ok |
7 |
Correct |
1 ms |
2396 KB |
ok |
8 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
2396 KB |
ok |
11 |
Correct |
1 ms |
2396 KB |
ok |
12 |
Correct |
0 ms |
2396 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
2392 KB |
ok |
5 |
Correct |
1 ms |
2396 KB |
ok |
6 |
Correct |
1 ms |
2392 KB |
ok |
7 |
Correct |
0 ms |
2396 KB |
ok |
8 |
Correct |
1 ms |
2396 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
2396 KB |
ok |
12 |
Correct |
1 ms |
2396 KB |
ok |
13 |
Correct |
0 ms |
2396 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
1 ms |
4696 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 |
0 ms |
344 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
4444 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 |
4444 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
1 ms |
2392 KB |
ok |
7 |
Correct |
1 ms |
2396 KB |
ok |
8 |
Correct |
1 ms |
2392 KB |
ok |
9 |
Correct |
0 ms |
2396 KB |
ok |
10 |
Correct |
1 ms |
2396 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
2396 KB |
ok |
14 |
Correct |
1 ms |
2396 KB |
ok |
15 |
Correct |
0 ms |
2396 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
4696 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 |
4444 KB |
ok |
22 |
Correct |
0 ms |
344 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
4444 KB |
ok |
25 |
Correct |
1 ms |
4444 KB |
ok |
26 |
Correct |
1 ms |
4444 KB |
ok |
27 |
Correct |
1 ms |
4444 KB |
ok |
28 |
Correct |
1 ms |
4444 KB |
ok |
29 |
Correct |
1 ms |
4440 KB |
ok |
30 |
Correct |
22 ms |
16988 KB |
ok |
31 |
Correct |
15 ms |
16988 KB |
ok |
32 |
Correct |
8 ms |
16988 KB |
ok |
33 |
Correct |
4 ms |
16988 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
5 ms |
16988 KB |
ok |
37 |
Correct |
7 ms |
17024 KB |
ok |
38 |
Correct |
7 ms |
16984 KB |
ok |
39 |
Correct |
9 ms |
16988 KB |
ok |
40 |
Correct |
27 ms |
17044 KB |
ok |
41 |
Correct |
31 ms |
16984 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
1 ms |
2392 KB |
ok |
7 |
Correct |
1 ms |
2396 KB |
ok |
8 |
Correct |
1 ms |
2392 KB |
ok |
9 |
Correct |
0 ms |
2396 KB |
ok |
10 |
Correct |
1 ms |
2396 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
2396 KB |
ok |
14 |
Correct |
1 ms |
2396 KB |
ok |
15 |
Correct |
0 ms |
2396 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
4696 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 |
4444 KB |
ok |
22 |
Correct |
0 ms |
344 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
4444 KB |
ok |
25 |
Correct |
1 ms |
4444 KB |
ok |
26 |
Correct |
1 ms |
4444 KB |
ok |
27 |
Correct |
1 ms |
4444 KB |
ok |
28 |
Correct |
1 ms |
4444 KB |
ok |
29 |
Correct |
1 ms |
4440 KB |
ok |
30 |
Correct |
22 ms |
16988 KB |
ok |
31 |
Correct |
15 ms |
16988 KB |
ok |
32 |
Correct |
8 ms |
16988 KB |
ok |
33 |
Correct |
4 ms |
16988 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
5 ms |
16988 KB |
ok |
37 |
Correct |
7 ms |
17024 KB |
ok |
38 |
Correct |
7 ms |
16984 KB |
ok |
39 |
Correct |
9 ms |
16988 KB |
ok |
40 |
Correct |
27 ms |
17044 KB |
ok |
41 |
Correct |
31 ms |
16984 KB |
ok |
42 |
Partially correct |
34 ms |
17244 KB |
partial |
43 |
Partially correct |
29 ms |
12892 KB |
partial |
44 |
Partially correct |
33 ms |
22040 KB |
partial |
45 |
Partially correct |
33 ms |
22356 KB |
partial |
46 |
Partially correct |
32 ms |
20060 KB |
partial |
47 |
Partially correct |
33 ms |
22876 KB |
partial |
48 |
Correct |
22 ms |
8540 KB |
ok |
49 |
Partially correct |
22 ms |
9820 KB |
partial |
50 |
Partially correct |
26 ms |
13140 KB |
partial |
51 |
Partially correct |
20 ms |
3416 KB |
partial |
52 |
Partially correct |
20 ms |
5212 KB |
partial |
53 |
Partially correct |
16 ms |
3932 KB |
partial |
54 |
Partially correct |
17 ms |
4700 KB |
partial |
55 |
Partially correct |
18 ms |
5532 KB |
partial |
56 |
Partially correct |
22 ms |
11352 KB |
partial |
57 |
Partially correct |
28 ms |
18000 KB |
partial |
58 |
Partially correct |
33 ms |
17268 KB |
partial |
59 |
Partially correct |
28 ms |
15764 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
ok |
2 |
Correct |
0 ms |
348 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 |
2396 KB |
ok |
8 |
Partially correct |
2 ms |
1112 KB |
partial |
9 |
Partially correct |
35 ms |
22964 KB |
partial |
10 |
Partially correct |
603 ms |
361244 KB |
partial |
11 |
Correct |
1 ms |
2392 KB |
ok |
12 |
Correct |
1 ms |
2396 KB |
ok |
13 |
Correct |
1 ms |
2392 KB |
ok |
14 |
Correct |
0 ms |
2396 KB |
ok |
15 |
Correct |
1 ms |
2396 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
2396 KB |
ok |
19 |
Correct |
1 ms |
2396 KB |
ok |
20 |
Correct |
0 ms |
2396 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
4696 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 |
4444 KB |
ok |
27 |
Correct |
0 ms |
344 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
1 ms |
4444 KB |
ok |
30 |
Correct |
1 ms |
4444 KB |
ok |
31 |
Correct |
1 ms |
4444 KB |
ok |
32 |
Correct |
1 ms |
4444 KB |
ok |
33 |
Correct |
1 ms |
4444 KB |
ok |
34 |
Correct |
1 ms |
4440 KB |
ok |
35 |
Correct |
22 ms |
16988 KB |
ok |
36 |
Correct |
15 ms |
16988 KB |
ok |
37 |
Correct |
8 ms |
16988 KB |
ok |
38 |
Correct |
4 ms |
16988 KB |
ok |
39 |
Correct |
0 ms |
348 KB |
ok |
40 |
Correct |
0 ms |
348 KB |
ok |
41 |
Correct |
5 ms |
16988 KB |
ok |
42 |
Correct |
7 ms |
17024 KB |
ok |
43 |
Correct |
7 ms |
16984 KB |
ok |
44 |
Correct |
9 ms |
16988 KB |
ok |
45 |
Correct |
27 ms |
17044 KB |
ok |
46 |
Correct |
31 ms |
16984 KB |
ok |
47 |
Partially correct |
34 ms |
17244 KB |
partial |
48 |
Partially correct |
29 ms |
12892 KB |
partial |
49 |
Partially correct |
33 ms |
22040 KB |
partial |
50 |
Partially correct |
33 ms |
22356 KB |
partial |
51 |
Partially correct |
32 ms |
20060 KB |
partial |
52 |
Partially correct |
33 ms |
22876 KB |
partial |
53 |
Correct |
22 ms |
8540 KB |
ok |
54 |
Partially correct |
22 ms |
9820 KB |
partial |
55 |
Partially correct |
26 ms |
13140 KB |
partial |
56 |
Partially correct |
20 ms |
3416 KB |
partial |
57 |
Partially correct |
20 ms |
5212 KB |
partial |
58 |
Partially correct |
16 ms |
3932 KB |
partial |
59 |
Partially correct |
17 ms |
4700 KB |
partial |
60 |
Partially correct |
18 ms |
5532 KB |
partial |
61 |
Partially correct |
22 ms |
11352 KB |
partial |
62 |
Partially correct |
28 ms |
18000 KB |
partial |
63 |
Partially correct |
33 ms |
17268 KB |
partial |
64 |
Partially correct |
28 ms |
15764 KB |
partial |
65 |
Partially correct |
504 ms |
271700 KB |
partial |
66 |
Partially correct |
245 ms |
48208 KB |
partial |
67 |
Partially correct |
238 ms |
48156 KB |
partial |
68 |
Partially correct |
560 ms |
359120 KB |
partial |
69 |
Partially correct |
549 ms |
348756 KB |
partial |
70 |
Partially correct |
536 ms |
334872 KB |
partial |
71 |
Partially correct |
575 ms |
359764 KB |
partial |
72 |
Partially correct |
570 ms |
360792 KB |
partial |
73 |
Correct |
374 ms |
128288 KB |
ok |
74 |
Correct |
375 ms |
130864 KB |
ok |
75 |
Partially correct |
377 ms |
130844 KB |
partial |
76 |
Partially correct |
435 ms |
204828 KB |
partial |
77 |
Partially correct |
446 ms |
204372 KB |
partial |
78 |
Partially correct |
234 ms |
48212 KB |
partial |
79 |
Partially correct |
249 ms |
48212 KB |
partial |
80 |
Partially correct |
235 ms |
48176 KB |
partial |
81 |
Partially correct |
232 ms |
48208 KB |
partial |
82 |
Partially correct |
241 ms |
48208 KB |
partial |
83 |
Partially correct |
241 ms |
48152 KB |
partial |
84 |
Partially correct |
268 ms |
63008 KB |
partial |
85 |
Partially correct |
263 ms |
57120 KB |
partial |
86 |
Partially correct |
287 ms |
70228 KB |
partial |
87 |
Partially correct |
285 ms |
80936 KB |
partial |
88 |
Partially correct |
384 ms |
174116 KB |
partial |
89 |
Partially correct |
552 ms |
331196 KB |
partial |
90 |
Partially correct |
458 ms |
249108 KB |
partial |
91 |
Partially correct |
473 ms |
240704 KB |
partial |
92 |
Partially correct |
229 ms |
48212 KB |
partial |
93 |
Partially correct |
240 ms |
48208 KB |
partial |
94 |
Partially correct |
238 ms |
48152 KB |
partial |
95 |
Partially correct |
232 ms |
48180 KB |
partial |
96 |
Partially correct |
235 ms |
48420 KB |
partial |
97 |
Partially correct |
231 ms |
48176 KB |
partial |
98 |
Partially correct |
235 ms |
48156 KB |
partial |
99 |
Partially correct |
228 ms |
48208 KB |
partial |
100 |
Partially correct |
493 ms |
282896 KB |
partial |
101 |
Partially correct |
264 ms |
83280 KB |
partial |
102 |
Partially correct |
273 ms |
87076 KB |
partial |
103 |
Partially correct |
459 ms |
266580 KB |
partial |
104 |
Partially correct |
279 ms |
99892 KB |
partial |
105 |
Partially correct |
281 ms |
104480 KB |
partial |
106 |
Partially correct |
430 ms |
228640 KB |
partial |
107 |
Partially correct |
401 ms |
207644 KB |
partial |
108 |
Partially correct |
235 ms |
48156 KB |
partial |
109 |
Partially correct |
239 ms |
48160 KB |
partial |