#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
int n;
vector<vector<int>> A;
int dp[31][31][31][31];
int cur;
int f(int i, int pos, int l, int r)
{
if (i < 0 || i >= n) return 0;
if (l > r) return 0;
if (pos >= n) return 0;
if (dp[i][pos][l][r] != -1) return dp[i][pos][l][r];
vector<int> v;
v.push_back(l - 1);
for (int j = l; j <= r; j++) if (A[i][j]) v.push_back(j);
v.push_back(r + 1);
int res = 0;
for (int j = 1; j < v.size(); j++)
{
if (i <= cur)
{
res = max(res, f(i - 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
res = max(res, f(cur + (pos - (cur - i)) + 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
}
else
{
res = max(res, f(i + 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
res = max(res, f(cur - (pos - (i - cur)) - 1, pos + 1, v[j - 1] + 1, v[j] - 1) + (v[j] - v[j - 1] - 1));
}
}
return dp[i][pos][l][r] = res;
}
int solve()
{
for (int i = 0; i < 31; i++)
{
for (int j = 0; j < 31; j++)
{
for (int k = 0; k < 31; k++)
{
for (int l = k; l < 31; l++) dp[i][j][k][l] = -1;
}
}
}
return f(cur, 0, 0, n - 1);
}
int calc(int i, int j)
{
return i * n + j * n - i * j;
}
int biggest_stadium(int N, vector<vector<int>> B)
{
n = N;
A = B;
int c = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
c += A[i][j];
}
}
if (c == 1)
{
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (A[i][j])
{
int i1 = n - i - 1, j1 = n - j - 1;
return max({calc(i, j), calc(i1, j), calc(i, j1), calc(i1, j1)});
}
}
}
}
int ok = 1, c1 = 0;
int l[N], r[N], cnt[N];
array<int, 2> mx = {-1, -1};
for (int i = 0; i < n; i++)
{
cnt[i] = 0;
l[i] = n + 1, r[i] = -1;
for (int j = 0; j < n; j++)
{
if (A[i][j]) continue;
cnt[i]++,
l[i] = min(l[i], j), r[i] = max(r[i], j);
}
if (!cnt[i]) continue;
if (cnt[i] != r[i] - l[i] + 1) ok = 0;
c1++;
mx = max(mx, {cnt[i], i});
}
if (N > 30)
{
assert(mx[1] != -1);
int lx = mx[1] - 1, rx = mx[1] + 1;
int last = mx[1];
while (lx >= 0 || rx < N)
{
if (lx >= 0 && cnt[lx] && (rx == N || cnt[lx] >= cnt[rx]))
{
if (!(l[last] <= l[lx] && r[lx] <= r[last]))
{
ok = 0;
break;
}
last = lx;
lx--;
}
else if (rx < N && cnt[rx] && (lx == -1 || cnt[rx] >= cnt[lx]))
{
if (!(l[last] <= l[rx] && r[rx] <= r[last]))
{
ok = 0;
break;
}
last = rx;
rx++;
}
else break;
}
if (rx - lx - 1 == c1 && ok)
{
return n * n - c;
}
return 0;
}
int res = 0;
for (cur = 0; cur < n; cur++)
{
res = max(res, solve());
}
return res;
}
Compilation message
soccer.cpp: In function 'int f(int, int, int, int)':
soccer.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int j = 1; j < v.size(); j++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 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 |
1 ms |
3932 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
348 KB |
ok |
8 |
Correct |
12 ms |
3420 KB |
ok |
9 |
Correct |
203 ms |
47404 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
3 ms |
3932 KB |
ok |
4 |
Correct |
2 ms |
3932 KB |
ok |
5 |
Correct |
2 ms |
3932 KB |
ok |
6 |
Correct |
3 ms |
3932 KB |
ok |
7 |
Correct |
4 ms |
3932 KB |
ok |
8 |
Correct |
2 ms |
3932 KB |
ok |
9 |
Correct |
2 ms |
4048 KB |
ok |
10 |
Correct |
2 ms |
3932 KB |
ok |
11 |
Correct |
3 ms |
3976 KB |
ok |
12 |
Correct |
2 ms |
3932 KB |
ok |
13 |
Correct |
2 ms |
3932 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
3 ms |
3932 KB |
ok |
5 |
Correct |
2 ms |
3932 KB |
ok |
6 |
Correct |
2 ms |
3932 KB |
ok |
7 |
Correct |
3 ms |
3932 KB |
ok |
8 |
Correct |
4 ms |
3932 KB |
ok |
9 |
Correct |
2 ms |
3932 KB |
ok |
10 |
Correct |
2 ms |
4048 KB |
ok |
11 |
Correct |
2 ms |
3932 KB |
ok |
12 |
Correct |
3 ms |
3976 KB |
ok |
13 |
Correct |
2 ms |
3932 KB |
ok |
14 |
Correct |
2 ms |
3932 KB |
ok |
15 |
Correct |
3 ms |
3932 KB |
ok |
16 |
Correct |
3 ms |
3932 KB |
ok |
17 |
Correct |
3 ms |
4024 KB |
ok |
18 |
Correct |
3 ms |
3932 KB |
ok |
19 |
Correct |
3 ms |
3932 KB |
ok |
20 |
Correct |
3 ms |
3928 KB |
ok |
21 |
Correct |
3 ms |
3932 KB |
ok |
22 |
Correct |
3 ms |
3932 KB |
ok |
23 |
Correct |
4 ms |
3932 KB |
ok |
24 |
Correct |
4 ms |
3932 KB |
ok |
25 |
Correct |
4 ms |
3932 KB |
ok |
26 |
Correct |
4 ms |
3932 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 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 |
3 ms |
3932 KB |
ok |
7 |
Correct |
2 ms |
3932 KB |
ok |
8 |
Correct |
2 ms |
3932 KB |
ok |
9 |
Correct |
3 ms |
3932 KB |
ok |
10 |
Correct |
4 ms |
3932 KB |
ok |
11 |
Correct |
2 ms |
3932 KB |
ok |
12 |
Correct |
2 ms |
4048 KB |
ok |
13 |
Correct |
2 ms |
3932 KB |
ok |
14 |
Correct |
3 ms |
3976 KB |
ok |
15 |
Correct |
2 ms |
3932 KB |
ok |
16 |
Correct |
2 ms |
3932 KB |
ok |
17 |
Correct |
3 ms |
3932 KB |
ok |
18 |
Correct |
3 ms |
3932 KB |
ok |
19 |
Correct |
3 ms |
4024 KB |
ok |
20 |
Correct |
3 ms |
3932 KB |
ok |
21 |
Correct |
3 ms |
3932 KB |
ok |
22 |
Correct |
3 ms |
3928 KB |
ok |
23 |
Correct |
3 ms |
3932 KB |
ok |
24 |
Correct |
3 ms |
3932 KB |
ok |
25 |
Correct |
4 ms |
3932 KB |
ok |
26 |
Correct |
4 ms |
3932 KB |
ok |
27 |
Correct |
4 ms |
3932 KB |
ok |
28 |
Correct |
4 ms |
3932 KB |
ok |
29 |
Correct |
3 ms |
3932 KB |
ok |
30 |
Correct |
12 ms |
4060 KB |
ok |
31 |
Correct |
11 ms |
4064 KB |
ok |
32 |
Correct |
10 ms |
3932 KB |
ok |
33 |
Correct |
10 ms |
4056 KB |
ok |
34 |
Correct |
12 ms |
3932 KB |
ok |
35 |
Correct |
11 ms |
4052 KB |
ok |
36 |
Correct |
11 ms |
3932 KB |
ok |
37 |
Correct |
10 ms |
3932 KB |
ok |
38 |
Correct |
10 ms |
3932 KB |
ok |
39 |
Correct |
11 ms |
3932 KB |
ok |
40 |
Correct |
11 ms |
3928 KB |
ok |
41 |
Correct |
11 ms |
3932 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 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 |
3 ms |
3932 KB |
ok |
7 |
Correct |
2 ms |
3932 KB |
ok |
8 |
Correct |
2 ms |
3932 KB |
ok |
9 |
Correct |
3 ms |
3932 KB |
ok |
10 |
Correct |
4 ms |
3932 KB |
ok |
11 |
Correct |
2 ms |
3932 KB |
ok |
12 |
Correct |
2 ms |
4048 KB |
ok |
13 |
Correct |
2 ms |
3932 KB |
ok |
14 |
Correct |
3 ms |
3976 KB |
ok |
15 |
Correct |
2 ms |
3932 KB |
ok |
16 |
Correct |
2 ms |
3932 KB |
ok |
17 |
Correct |
3 ms |
3932 KB |
ok |
18 |
Correct |
3 ms |
3932 KB |
ok |
19 |
Correct |
3 ms |
4024 KB |
ok |
20 |
Correct |
3 ms |
3932 KB |
ok |
21 |
Correct |
3 ms |
3932 KB |
ok |
22 |
Correct |
3 ms |
3928 KB |
ok |
23 |
Correct |
3 ms |
3932 KB |
ok |
24 |
Correct |
3 ms |
3932 KB |
ok |
25 |
Correct |
4 ms |
3932 KB |
ok |
26 |
Correct |
4 ms |
3932 KB |
ok |
27 |
Correct |
4 ms |
3932 KB |
ok |
28 |
Correct |
4 ms |
3932 KB |
ok |
29 |
Correct |
3 ms |
3932 KB |
ok |
30 |
Correct |
12 ms |
4060 KB |
ok |
31 |
Correct |
11 ms |
4064 KB |
ok |
32 |
Correct |
10 ms |
3932 KB |
ok |
33 |
Correct |
10 ms |
4056 KB |
ok |
34 |
Correct |
12 ms |
3932 KB |
ok |
35 |
Correct |
11 ms |
4052 KB |
ok |
36 |
Correct |
11 ms |
3932 KB |
ok |
37 |
Correct |
10 ms |
3932 KB |
ok |
38 |
Correct |
10 ms |
3932 KB |
ok |
39 |
Correct |
11 ms |
3932 KB |
ok |
40 |
Correct |
11 ms |
3928 KB |
ok |
41 |
Correct |
11 ms |
3932 KB |
ok |
42 |
Partially correct |
13 ms |
3420 KB |
partial |
43 |
Partially correct |
14 ms |
3420 KB |
partial |
44 |
Partially correct |
13 ms |
3232 KB |
partial |
45 |
Partially correct |
17 ms |
3420 KB |
partial |
46 |
Partially correct |
14 ms |
3420 KB |
partial |
47 |
Partially correct |
13 ms |
3420 KB |
partial |
48 |
Correct |
13 ms |
3416 KB |
ok |
49 |
Partially correct |
13 ms |
3928 KB |
partial |
50 |
Partially correct |
13 ms |
3676 KB |
partial |
51 |
Partially correct |
13 ms |
3676 KB |
partial |
52 |
Partially correct |
13 ms |
3724 KB |
partial |
53 |
Partially correct |
13 ms |
3672 KB |
partial |
54 |
Partially correct |
19 ms |
3668 KB |
partial |
55 |
Partially correct |
13 ms |
3672 KB |
partial |
56 |
Partially correct |
13 ms |
3676 KB |
partial |
57 |
Partially correct |
13 ms |
3932 KB |
partial |
58 |
Partially correct |
15 ms |
3672 KB |
partial |
59 |
Partially correct |
14 ms |
3676 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
3932 KB |
ok |
2 |
Correct |
1 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 |
1 ms |
3932 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
348 KB |
ok |
9 |
Correct |
12 ms |
3420 KB |
ok |
10 |
Correct |
203 ms |
47404 KB |
ok |
11 |
Correct |
3 ms |
3932 KB |
ok |
12 |
Correct |
2 ms |
3932 KB |
ok |
13 |
Correct |
2 ms |
3932 KB |
ok |
14 |
Correct |
3 ms |
3932 KB |
ok |
15 |
Correct |
4 ms |
3932 KB |
ok |
16 |
Correct |
2 ms |
3932 KB |
ok |
17 |
Correct |
2 ms |
4048 KB |
ok |
18 |
Correct |
2 ms |
3932 KB |
ok |
19 |
Correct |
3 ms |
3976 KB |
ok |
20 |
Correct |
2 ms |
3932 KB |
ok |
21 |
Correct |
2 ms |
3932 KB |
ok |
22 |
Correct |
3 ms |
3932 KB |
ok |
23 |
Correct |
3 ms |
3932 KB |
ok |
24 |
Correct |
3 ms |
4024 KB |
ok |
25 |
Correct |
3 ms |
3932 KB |
ok |
26 |
Correct |
3 ms |
3932 KB |
ok |
27 |
Correct |
3 ms |
3928 KB |
ok |
28 |
Correct |
3 ms |
3932 KB |
ok |
29 |
Correct |
3 ms |
3932 KB |
ok |
30 |
Correct |
4 ms |
3932 KB |
ok |
31 |
Correct |
4 ms |
3932 KB |
ok |
32 |
Correct |
4 ms |
3932 KB |
ok |
33 |
Correct |
4 ms |
3932 KB |
ok |
34 |
Correct |
3 ms |
3932 KB |
ok |
35 |
Correct |
12 ms |
4060 KB |
ok |
36 |
Correct |
11 ms |
4064 KB |
ok |
37 |
Correct |
10 ms |
3932 KB |
ok |
38 |
Correct |
10 ms |
4056 KB |
ok |
39 |
Correct |
12 ms |
3932 KB |
ok |
40 |
Correct |
11 ms |
4052 KB |
ok |
41 |
Correct |
11 ms |
3932 KB |
ok |
42 |
Correct |
10 ms |
3932 KB |
ok |
43 |
Correct |
10 ms |
3932 KB |
ok |
44 |
Correct |
11 ms |
3932 KB |
ok |
45 |
Correct |
11 ms |
3928 KB |
ok |
46 |
Correct |
11 ms |
3932 KB |
ok |
47 |
Partially correct |
13 ms |
3420 KB |
partial |
48 |
Partially correct |
14 ms |
3420 KB |
partial |
49 |
Partially correct |
13 ms |
3232 KB |
partial |
50 |
Partially correct |
17 ms |
3420 KB |
partial |
51 |
Partially correct |
14 ms |
3420 KB |
partial |
52 |
Partially correct |
13 ms |
3420 KB |
partial |
53 |
Correct |
13 ms |
3416 KB |
ok |
54 |
Partially correct |
13 ms |
3928 KB |
partial |
55 |
Partially correct |
13 ms |
3676 KB |
partial |
56 |
Partially correct |
13 ms |
3676 KB |
partial |
57 |
Partially correct |
13 ms |
3724 KB |
partial |
58 |
Partially correct |
13 ms |
3672 KB |
partial |
59 |
Partially correct |
19 ms |
3668 KB |
partial |
60 |
Partially correct |
13 ms |
3672 KB |
partial |
61 |
Partially correct |
13 ms |
3676 KB |
partial |
62 |
Partially correct |
13 ms |
3932 KB |
partial |
63 |
Partially correct |
15 ms |
3672 KB |
partial |
64 |
Partially correct |
14 ms |
3676 KB |
partial |
65 |
Partially correct |
223 ms |
55308 KB |
partial |
66 |
Partially correct |
221 ms |
55376 KB |
partial |
67 |
Partially correct |
211 ms |
55380 KB |
partial |
68 |
Partially correct |
205 ms |
55380 KB |
partial |
69 |
Partially correct |
207 ms |
55440 KB |
partial |
70 |
Partially correct |
217 ms |
55380 KB |
partial |
71 |
Partially correct |
232 ms |
55640 KB |
partial |
72 |
Partially correct |
207 ms |
55632 KB |
partial |
73 |
Correct |
201 ms |
55376 KB |
ok |
74 |
Correct |
201 ms |
55380 KB |
ok |
75 |
Partially correct |
215 ms |
55376 KB |
partial |
76 |
Partially correct |
234 ms |
55304 KB |
partial |
77 |
Partially correct |
202 ms |
55376 KB |
partial |
78 |
Partially correct |
209 ms |
55376 KB |
partial |
79 |
Partially correct |
209 ms |
55380 KB |
partial |
80 |
Partially correct |
197 ms |
55308 KB |
partial |
81 |
Partially correct |
197 ms |
55200 KB |
partial |
82 |
Partially correct |
212 ms |
55316 KB |
partial |
83 |
Partially correct |
205 ms |
55456 KB |
partial |
84 |
Partially correct |
206 ms |
55380 KB |
partial |
85 |
Partially correct |
196 ms |
55628 KB |
partial |
86 |
Partially correct |
225 ms |
55376 KB |
partial |
87 |
Partially correct |
206 ms |
55380 KB |
partial |
88 |
Partially correct |
198 ms |
55436 KB |
partial |
89 |
Partially correct |
202 ms |
55376 KB |
partial |
90 |
Partially correct |
217 ms |
55380 KB |
partial |
91 |
Partially correct |
206 ms |
55380 KB |
partial |
92 |
Partially correct |
207 ms |
55380 KB |
partial |
93 |
Partially correct |
244 ms |
55308 KB |
partial |
94 |
Partially correct |
207 ms |
55304 KB |
partial |
95 |
Partially correct |
235 ms |
55324 KB |
partial |
96 |
Partially correct |
228 ms |
55376 KB |
partial |
97 |
Partially correct |
208 ms |
55376 KB |
partial |
98 |
Partially correct |
218 ms |
55376 KB |
partial |
99 |
Partially correct |
218 ms |
55440 KB |
partial |
100 |
Partially correct |
220 ms |
55312 KB |
partial |
101 |
Partially correct |
222 ms |
55312 KB |
partial |
102 |
Partially correct |
277 ms |
55312 KB |
partial |
103 |
Partially correct |
226 ms |
55308 KB |
partial |
104 |
Partially correct |
249 ms |
55436 KB |
partial |
105 |
Partially correct |
220 ms |
55376 KB |
partial |
106 |
Partially correct |
244 ms |
55308 KB |
partial |
107 |
Partially correct |
216 ms |
55440 KB |
partial |
108 |
Partially correct |
220 ms |
55376 KB |
partial |
109 |
Partially correct |
266 ms |
55380 KB |
partial |