#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 2010;
int n;
bool a[N][N];
vector<int> arr[N];
int check_valid() {
for(int col = 0; col < n; col++) {
for(int row = 0; row < n; row++) if (a[row][col] == 0) arr[col].push_back(row);
}
int st = 0;
while (st < n && arr[st].empty()) st++;
if (st == n) return 0;
int ed = st;
while (ed < n && !arr[ed].empty()) ed++; ed--;
for(int i = 1; i < st; i++) if (!arr[i].empty()) return 0;
for(int i = ed + 1; i < n; i++) if (!arr[i].empty()) return 0;
for(int i = st; i <= ed; i++) if (arr[i].size() != arr[i].back() - arr[i][0] + 1) return 0;
int cnt = 0;
for(int i = st; i <= ed; i++) cnt += arr[i].size();
int L = max(arr[st][0], arr[ed][0]);
int R = min(arr[st].back(), arr[ed].back());
while (st <= ed) {
if (arr[st].size() <= arr[ed].size()) {
if (arr[st][0] <= L && arr[st].back() >= R) {
L = arr[st][0];
R = arr[st].back();
st++;
}
else return 0;
}
else {
if (arr[ed][0] <= L && arr[ed].back() >= R) {
L = arr[ed][0];
R = arr[ed].back();
ed--;
}
else return 0;
}
}
return cnt;
}
namespace sub4 {
const int N = 51;
int pref[N][N];
int dp[N][N][N][N];
int solve() {
for(int i = 0; i < n; i++) {
pref[i][0] = a[i][0];
for(int j = 1; j < n; j++) pref[i][j] = pref[i][j - 1] + a[i][j];
}
auto check = [&] (int i, int l, int r) {
int sum = pref[i][r];
if (l > 0) sum -= pref[i][l - 1];
return sum == 0;
};
int ans = 0;
// cout << check(1, 1, 2) << endl;
memset(dp, -61, sizeof(dp));
for(int i = 0; i < n; i++) {
for(int u = 0; u < n; u++) for(int v = u; v < n; v++) if (check(i, u, v)) dp[i][i][u][v] = v - u + 1;
}
for(int x = n - 1; x >= 0; x--) for(int y = x; y <= n; y++) {
for(int u = 0; u < n; u++) for(int v = u; v < n; v++) {
for(int _u = 0; _u <= u; _u++) for(int _v = v; _v < n; _v++) {
if (y + 1 < n && check(y + 1, u, v)) dp[x][y + 1][u][v] = max(dp[x][y + 1][u][v], dp[x][y][_u][_v] + v - u + 1);
if (x > 0 && check(x - 1, u, v)) dp[x - 1][y][u][v] = max(dp[x - 1][y][u][v], dp[x][y][_u][_v] + v - u + 1);
}
ans = max(ans, dp[x][y][u][v]);
}
}
return ans;
}
}
namespace sub5 {
int solve() {
return 0;
}
}
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
n = N;
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) a[i][j] = F[i][j];
if (n <= 30) return sub4::solve();
// if (n <= 500) return sub5::solve();
return check_valid();
}
#ifdef ngu
int main()
{
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int N;
assert(1 == scanf("%d", &N));
std::vector<std::vector<int>> F(N, std::vector<int>(N));
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
assert(1 == scanf("%d", &F[i][j]));
}
}
fclose(stdin);
int res = biggest_stadium(N, F);
printf("%d\n", res);
fclose(stdout);
return 0;
}
#endif // ngu
Compilation message
soccer.cpp: In function 'int check_valid()':
soccer.cpp:23:3: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
23 | while (ed < n && !arr[ed].empty()) ed++; ed--;
| ^~~~~
soccer.cpp:23:44: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
23 | while (ed < n && !arr[ed].empty()) ed++; ed--;
| ^~
soccer.cpp:26:51: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} [-Wsign-compare]
26 | for(int i = st; i <= ed; i++) if (arr[i].size() != arr[i].back() - arr[i][0] + 1) return 0;
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26972 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26816 KB |
ok |
2 |
Correct |
10 ms |
26972 KB |
ok |
3 |
Correct |
12 ms |
26972 KB |
ok |
4 |
Correct |
10 ms |
27228 KB |
ok |
5 |
Correct |
10 ms |
26976 KB |
ok |
6 |
Correct |
10 ms |
26968 KB |
ok |
7 |
Partially correct |
1 ms |
604 KB |
partial |
8 |
Partially correct |
20 ms |
4816 KB |
partial |
9 |
Partially correct |
298 ms |
55988 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26816 KB |
ok |
2 |
Correct |
10 ms |
26972 KB |
ok |
3 |
Correct |
9 ms |
26968 KB |
ok |
4 |
Correct |
10 ms |
26800 KB |
ok |
5 |
Correct |
10 ms |
26972 KB |
ok |
6 |
Correct |
10 ms |
26880 KB |
ok |
7 |
Correct |
12 ms |
27124 KB |
ok |
8 |
Correct |
10 ms |
26968 KB |
ok |
9 |
Correct |
11 ms |
26968 KB |
ok |
10 |
Correct |
10 ms |
26972 KB |
ok |
11 |
Correct |
13 ms |
26972 KB |
ok |
12 |
Correct |
10 ms |
26972 KB |
ok |
13 |
Correct |
10 ms |
26796 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26972 KB |
ok |
2 |
Correct |
10 ms |
26816 KB |
ok |
3 |
Correct |
10 ms |
26972 KB |
ok |
4 |
Correct |
9 ms |
26968 KB |
ok |
5 |
Correct |
10 ms |
26800 KB |
ok |
6 |
Correct |
10 ms |
26972 KB |
ok |
7 |
Correct |
10 ms |
26880 KB |
ok |
8 |
Correct |
12 ms |
27124 KB |
ok |
9 |
Correct |
10 ms |
26968 KB |
ok |
10 |
Correct |
11 ms |
26968 KB |
ok |
11 |
Correct |
10 ms |
26972 KB |
ok |
12 |
Correct |
13 ms |
26972 KB |
ok |
13 |
Correct |
10 ms |
26972 KB |
ok |
14 |
Correct |
10 ms |
26796 KB |
ok |
15 |
Correct |
12 ms |
26972 KB |
ok |
16 |
Correct |
10 ms |
26972 KB |
ok |
17 |
Correct |
10 ms |
26816 KB |
ok |
18 |
Correct |
10 ms |
26972 KB |
ok |
19 |
Correct |
10 ms |
26972 KB |
ok |
20 |
Correct |
10 ms |
26972 KB |
ok |
21 |
Correct |
13 ms |
26972 KB |
ok |
22 |
Correct |
10 ms |
26972 KB |
ok |
23 |
Correct |
10 ms |
26968 KB |
ok |
24 |
Correct |
10 ms |
26972 KB |
ok |
25 |
Correct |
10 ms |
26972 KB |
ok |
26 |
Correct |
12 ms |
26972 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26972 KB |
ok |
2 |
Correct |
10 ms |
26816 KB |
ok |
3 |
Correct |
10 ms |
26972 KB |
ok |
4 |
Correct |
12 ms |
26972 KB |
ok |
5 |
Correct |
10 ms |
27228 KB |
ok |
6 |
Correct |
9 ms |
26968 KB |
ok |
7 |
Correct |
10 ms |
26800 KB |
ok |
8 |
Correct |
10 ms |
26972 KB |
ok |
9 |
Correct |
10 ms |
26880 KB |
ok |
10 |
Correct |
12 ms |
27124 KB |
ok |
11 |
Correct |
10 ms |
26968 KB |
ok |
12 |
Correct |
11 ms |
26968 KB |
ok |
13 |
Correct |
10 ms |
26972 KB |
ok |
14 |
Correct |
13 ms |
26972 KB |
ok |
15 |
Correct |
10 ms |
26972 KB |
ok |
16 |
Correct |
10 ms |
26796 KB |
ok |
17 |
Correct |
12 ms |
26972 KB |
ok |
18 |
Correct |
10 ms |
26972 KB |
ok |
19 |
Correct |
10 ms |
26816 KB |
ok |
20 |
Correct |
10 ms |
26972 KB |
ok |
21 |
Correct |
10 ms |
26972 KB |
ok |
22 |
Correct |
10 ms |
26972 KB |
ok |
23 |
Correct |
13 ms |
26972 KB |
ok |
24 |
Correct |
10 ms |
26972 KB |
ok |
25 |
Correct |
10 ms |
26968 KB |
ok |
26 |
Correct |
10 ms |
26972 KB |
ok |
27 |
Correct |
10 ms |
26972 KB |
ok |
28 |
Correct |
12 ms |
26972 KB |
ok |
29 |
Correct |
9 ms |
26972 KB |
ok |
30 |
Correct |
63 ms |
27024 KB |
ok |
31 |
Correct |
59 ms |
26972 KB |
ok |
32 |
Correct |
58 ms |
26968 KB |
ok |
33 |
Correct |
45 ms |
26968 KB |
ok |
34 |
Correct |
52 ms |
27024 KB |
ok |
35 |
Correct |
52 ms |
27024 KB |
ok |
36 |
Correct |
44 ms |
27020 KB |
ok |
37 |
Correct |
51 ms |
27016 KB |
ok |
38 |
Correct |
47 ms |
26968 KB |
ok |
39 |
Correct |
51 ms |
27056 KB |
ok |
40 |
Correct |
69 ms |
27016 KB |
ok |
41 |
Correct |
70 ms |
27020 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26972 KB |
ok |
2 |
Correct |
10 ms |
26816 KB |
ok |
3 |
Correct |
10 ms |
26972 KB |
ok |
4 |
Correct |
12 ms |
26972 KB |
ok |
5 |
Correct |
10 ms |
27228 KB |
ok |
6 |
Correct |
9 ms |
26968 KB |
ok |
7 |
Correct |
10 ms |
26800 KB |
ok |
8 |
Correct |
10 ms |
26972 KB |
ok |
9 |
Correct |
10 ms |
26880 KB |
ok |
10 |
Correct |
12 ms |
27124 KB |
ok |
11 |
Correct |
10 ms |
26968 KB |
ok |
12 |
Correct |
11 ms |
26968 KB |
ok |
13 |
Correct |
10 ms |
26972 KB |
ok |
14 |
Correct |
13 ms |
26972 KB |
ok |
15 |
Correct |
10 ms |
26972 KB |
ok |
16 |
Correct |
10 ms |
26796 KB |
ok |
17 |
Correct |
12 ms |
26972 KB |
ok |
18 |
Correct |
10 ms |
26972 KB |
ok |
19 |
Correct |
10 ms |
26816 KB |
ok |
20 |
Correct |
10 ms |
26972 KB |
ok |
21 |
Correct |
10 ms |
26972 KB |
ok |
22 |
Correct |
10 ms |
26972 KB |
ok |
23 |
Correct |
13 ms |
26972 KB |
ok |
24 |
Correct |
10 ms |
26972 KB |
ok |
25 |
Correct |
10 ms |
26968 KB |
ok |
26 |
Correct |
10 ms |
26972 KB |
ok |
27 |
Correct |
10 ms |
26972 KB |
ok |
28 |
Correct |
12 ms |
26972 KB |
ok |
29 |
Correct |
9 ms |
26972 KB |
ok |
30 |
Correct |
63 ms |
27024 KB |
ok |
31 |
Correct |
59 ms |
26972 KB |
ok |
32 |
Correct |
58 ms |
26968 KB |
ok |
33 |
Correct |
45 ms |
26968 KB |
ok |
34 |
Correct |
52 ms |
27024 KB |
ok |
35 |
Correct |
52 ms |
27024 KB |
ok |
36 |
Correct |
44 ms |
27020 KB |
ok |
37 |
Correct |
51 ms |
27016 KB |
ok |
38 |
Correct |
47 ms |
26968 KB |
ok |
39 |
Correct |
51 ms |
27056 KB |
ok |
40 |
Correct |
69 ms |
27016 KB |
ok |
41 |
Correct |
70 ms |
27020 KB |
ok |
42 |
Partially correct |
18 ms |
4956 KB |
partial |
43 |
Partially correct |
19 ms |
4812 KB |
partial |
44 |
Partially correct |
19 ms |
4820 KB |
partial |
45 |
Partially correct |
18 ms |
4956 KB |
partial |
46 |
Partially correct |
19 ms |
4916 KB |
partial |
47 |
Partially correct |
18 ms |
4952 KB |
partial |
48 |
Correct |
17 ms |
4440 KB |
ok |
49 |
Partially correct |
17 ms |
4440 KB |
partial |
50 |
Partially correct |
17 ms |
4552 KB |
partial |
51 |
Partially correct |
18 ms |
4956 KB |
partial |
52 |
Partially correct |
20 ms |
3920 KB |
partial |
53 |
Partially correct |
17 ms |
3928 KB |
partial |
54 |
Partially correct |
20 ms |
4096 KB |
partial |
55 |
Partially correct |
17 ms |
4224 KB |
partial |
56 |
Partially correct |
17 ms |
4444 KB |
partial |
57 |
Partially correct |
20 ms |
4948 KB |
partial |
58 |
Partially correct |
18 ms |
4952 KB |
partial |
59 |
Partially correct |
17 ms |
4956 KB |
partial |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
26972 KB |
ok |
2 |
Correct |
10 ms |
26816 KB |
ok |
3 |
Correct |
10 ms |
26972 KB |
ok |
4 |
Correct |
12 ms |
26972 KB |
ok |
5 |
Correct |
10 ms |
27228 KB |
ok |
6 |
Correct |
10 ms |
26976 KB |
ok |
7 |
Correct |
10 ms |
26968 KB |
ok |
8 |
Partially correct |
1 ms |
604 KB |
partial |
9 |
Partially correct |
20 ms |
4816 KB |
partial |
10 |
Partially correct |
298 ms |
55988 KB |
partial |
11 |
Correct |
9 ms |
26968 KB |
ok |
12 |
Correct |
10 ms |
26800 KB |
ok |
13 |
Correct |
10 ms |
26972 KB |
ok |
14 |
Correct |
10 ms |
26880 KB |
ok |
15 |
Correct |
12 ms |
27124 KB |
ok |
16 |
Correct |
10 ms |
26968 KB |
ok |
17 |
Correct |
11 ms |
26968 KB |
ok |
18 |
Correct |
10 ms |
26972 KB |
ok |
19 |
Correct |
13 ms |
26972 KB |
ok |
20 |
Correct |
10 ms |
26972 KB |
ok |
21 |
Correct |
10 ms |
26796 KB |
ok |
22 |
Correct |
12 ms |
26972 KB |
ok |
23 |
Correct |
10 ms |
26972 KB |
ok |
24 |
Correct |
10 ms |
26816 KB |
ok |
25 |
Correct |
10 ms |
26972 KB |
ok |
26 |
Correct |
10 ms |
26972 KB |
ok |
27 |
Correct |
10 ms |
26972 KB |
ok |
28 |
Correct |
13 ms |
26972 KB |
ok |
29 |
Correct |
10 ms |
26972 KB |
ok |
30 |
Correct |
10 ms |
26968 KB |
ok |
31 |
Correct |
10 ms |
26972 KB |
ok |
32 |
Correct |
10 ms |
26972 KB |
ok |
33 |
Correct |
12 ms |
26972 KB |
ok |
34 |
Correct |
9 ms |
26972 KB |
ok |
35 |
Correct |
63 ms |
27024 KB |
ok |
36 |
Correct |
59 ms |
26972 KB |
ok |
37 |
Correct |
58 ms |
26968 KB |
ok |
38 |
Correct |
45 ms |
26968 KB |
ok |
39 |
Correct |
52 ms |
27024 KB |
ok |
40 |
Correct |
52 ms |
27024 KB |
ok |
41 |
Correct |
44 ms |
27020 KB |
ok |
42 |
Correct |
51 ms |
27016 KB |
ok |
43 |
Correct |
47 ms |
26968 KB |
ok |
44 |
Correct |
51 ms |
27056 KB |
ok |
45 |
Correct |
69 ms |
27016 KB |
ok |
46 |
Correct |
70 ms |
27020 KB |
ok |
47 |
Partially correct |
18 ms |
4956 KB |
partial |
48 |
Partially correct |
19 ms |
4812 KB |
partial |
49 |
Partially correct |
19 ms |
4820 KB |
partial |
50 |
Partially correct |
18 ms |
4956 KB |
partial |
51 |
Partially correct |
19 ms |
4916 KB |
partial |
52 |
Partially correct |
18 ms |
4952 KB |
partial |
53 |
Correct |
17 ms |
4440 KB |
ok |
54 |
Partially correct |
17 ms |
4440 KB |
partial |
55 |
Partially correct |
17 ms |
4552 KB |
partial |
56 |
Partially correct |
18 ms |
4956 KB |
partial |
57 |
Partially correct |
20 ms |
3920 KB |
partial |
58 |
Partially correct |
17 ms |
3928 KB |
partial |
59 |
Partially correct |
20 ms |
4096 KB |
partial |
60 |
Partially correct |
17 ms |
4224 KB |
partial |
61 |
Partially correct |
17 ms |
4444 KB |
partial |
62 |
Partially correct |
20 ms |
4948 KB |
partial |
63 |
Partially correct |
18 ms |
4952 KB |
partial |
64 |
Partially correct |
17 ms |
4956 KB |
partial |
65 |
Partially correct |
288 ms |
59596 KB |
partial |
66 |
Partially correct |
310 ms |
51672 KB |
partial |
67 |
Partially correct |
271 ms |
45536 KB |
partial |
68 |
Partially correct |
291 ms |
59720 KB |
partial |
69 |
Partially correct |
278 ms |
59588 KB |
partial |
70 |
Partially correct |
318 ms |
59720 KB |
partial |
71 |
Partially correct |
286 ms |
59588 KB |
partial |
72 |
Partially correct |
273 ms |
59580 KB |
partial |
73 |
Correct |
269 ms |
54236 KB |
ok |
74 |
Correct |
281 ms |
54352 KB |
ok |
75 |
Partially correct |
264 ms |
54220 KB |
partial |
76 |
Partially correct |
290 ms |
55628 KB |
partial |
77 |
Partially correct |
280 ms |
55756 KB |
partial |
78 |
Partially correct |
287 ms |
59472 KB |
partial |
79 |
Partially correct |
281 ms |
44616 KB |
partial |
80 |
Partially correct |
281 ms |
44872 KB |
partial |
81 |
Partially correct |
283 ms |
46032 KB |
partial |
82 |
Partially correct |
265 ms |
49608 KB |
partial |
83 |
Partially correct |
300 ms |
47560 KB |
partial |
84 |
Partially correct |
280 ms |
45636 KB |
partial |
85 |
Partially correct |
263 ms |
44880 KB |
partial |
86 |
Partially correct |
273 ms |
46668 KB |
partial |
87 |
Partially correct |
269 ms |
46940 KB |
partial |
88 |
Partially correct |
281 ms |
51732 KB |
partial |
89 |
Partially correct |
288 ms |
58056 KB |
partial |
90 |
Partially correct |
300 ms |
54728 KB |
partial |
91 |
Partially correct |
273 ms |
59336 KB |
partial |
92 |
Partially correct |
284 ms |
46012 KB |
partial |
93 |
Partially correct |
273 ms |
45772 KB |
partial |
94 |
Partially correct |
281 ms |
45392 KB |
partial |
95 |
Partially correct |
259 ms |
45512 KB |
partial |
96 |
Partially correct |
280 ms |
45628 KB |
partial |
97 |
Partially correct |
265 ms |
45608 KB |
partial |
98 |
Partially correct |
254 ms |
44624 KB |
partial |
99 |
Partially correct |
296 ms |
59336 KB |
partial |
100 |
Partially correct |
281 ms |
59712 KB |
partial |
101 |
Partially correct |
267 ms |
59728 KB |
partial |
102 |
Partially correct |
283 ms |
59624 KB |
partial |
103 |
Partially correct |
304 ms |
59724 KB |
partial |
104 |
Partially correct |
265 ms |
59600 KB |
partial |
105 |
Partially correct |
274 ms |
59596 KB |
partial |
106 |
Partially correct |
321 ms |
59724 KB |
partial |
107 |
Partially correct |
284 ms |
59724 KB |
partial |
108 |
Partially correct |
292 ms |
59468 KB |
partial |
109 |
Partially correct |
301 ms |
51736 KB |
partial |