// In the name of Allah
#include <bits/stdc++.h>
#include "soccer.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define F first
#define S second
#define endl '\n'
#define sep ' '
#define pb push_back
#define Mp make_pair
#define all(x) (x).begin(),(x).end()
#define len(x) ((ll) (x).size())
const int maxn = 2000 + 4;
int n;
int A[maxn][maxn];
vector<pii> ls;
int val1[maxn][maxn], val2[maxn][maxn];
pii val[maxn]; int dp[maxn][maxn];
bool cmp(pii i, pii j) {
return ((i.S - i.F) > (j.S - j.F));
}
bool is_ok() {
ls.clear();
for (int i = 0; i < n; i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (A[i][j] != A[i][x]) {
if (A[i][x] == 0) ls.pb(Mp(x, j - 1));
x = j;
}
}
if (A[i][x] == 0) ls.pb(Mp(x, n - 1));
}
sort(all(ls), cmp);
for (int i = 1; i < len(ls); i++) {
if (ls[i].F < ls[i - 1].F || ls[i].S > ls[i - 1].S) return 0;
}
return 1;
}
int check() {
int num = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) num += (A[i][j] == 0);
}
bool ok = 1;
ok &= is_ok();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) swap(A[i][j], A[j][i]);
}
ok &= is_ok();
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) swap(A[i][j], A[j][i]);
}
if (ok) return num;
else return 0;
}
int get_val(int x, int y) {
val[x] = Mp(val1[x][y], val2[x][y]);
int lx = x, rx = x;
for (int r = x + 1; r < n; r++) {
if (A[r][y] == 1) break;
val[r] = Mp(val1[r][y], val2[r][y]);
val[r].F = max(val[r].F, val[r - 1].F);
val[r].S = min(val[r].S, val[r - 1].S);
rx = r;
}
for (int r = x - 1; r >= 0; r--) {
if (A[r][y] == 1) break;
val[r] = Mp(val1[r][y], val2[r][y]);
val[r].F = max(val[r].F, val[r + 1].F);
val[r].S = min(val[r].S, val[r + 1].S);
lx = r;
}
for (int i = x; i >= lx; i--) {
for (int j = x; j <= rx; j++) {
int valx = min(val[i].S, val[j].S) - max(val[i].F, val[j].F) + 1;
if (i == x && j == x) {
dp[i][j] = valx;
}
else {
dp[i][j] = 0;
if (i + 1 <= x) {
dp[i][j] = max(dp[i][j], dp[i + 1][j] + valx);
}
if (j - 1 >= x) {
dp[i][j] = max(dp[i][j], dp[i][j - 1] + valx);
}
}
}
}
return dp[lx][rx];
}
int solve() {
int mx = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (A[i][j] == 1) continue;
mx = max(mx, get_val(i, j));
}
}
return mx;
}
int biggest_stadium(int N, vector<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 (A[i][j] == 1) ls.pb(Mp(i, j));
}
}
if (len(ls) == 0) return (n * n);
else if (len(ls) == 1) {
int i = ls.back().F, j = ls.back().S;
return (n * n) - (min(i + 1, n - i) * min(j + 1, n - j));
}
for (int i = 0; i < n; i++) {
int x = 0;
for (int j = 0; j < n; j++) {
if (A[i][j] != A[i][x]) x = j;
val1[i][j] = x;
}
x = n - 1;
for (int j = n - 1; j >= 0; j--) {
if (A[i][j] != A[i][x]) x = j;
val2[i][j] = x;
}
}
if (n <= 30) return solve();
else return check();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
2 ms |
2652 KB |
ok |
8 |
Correct |
24 ms |
5276 KB |
ok |
9 |
Correct |
197 ms |
49196 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
2392 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 |
Correct |
0 ms |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
ok |
2 |
Correct |
0 ms |
600 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
2392 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
0 ms |
2396 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 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 |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
344 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Correct |
0 ms |
344 KB |
ok |
25 |
Correct |
0 ms |
348 KB |
ok |
26 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
ok |
2 |
Correct |
0 ms |
600 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 |
0 ms |
348 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 |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
2396 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
344 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
1 ms |
348 KB |
ok |
26 |
Correct |
0 ms |
344 KB |
ok |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
1 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
860 KB |
ok |
31 |
Correct |
1 ms |
860 KB |
ok |
32 |
Correct |
1 ms |
860 KB |
ok |
33 |
Correct |
1 ms |
860 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
856 KB |
ok |
36 |
Correct |
1 ms |
860 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
0 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
2652 KB |
ok |
40 |
Correct |
1 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
860 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
ok |
2 |
Correct |
0 ms |
600 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 |
0 ms |
348 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 |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
2396 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
344 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
1 ms |
348 KB |
ok |
26 |
Correct |
0 ms |
344 KB |
ok |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
1 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
860 KB |
ok |
31 |
Correct |
1 ms |
860 KB |
ok |
32 |
Correct |
1 ms |
860 KB |
ok |
33 |
Correct |
1 ms |
860 KB |
ok |
34 |
Correct |
1 ms |
860 KB |
ok |
35 |
Correct |
1 ms |
856 KB |
ok |
36 |
Correct |
1 ms |
860 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
0 ms |
860 KB |
ok |
39 |
Correct |
1 ms |
2652 KB |
ok |
40 |
Correct |
1 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
860 KB |
ok |
42 |
Partially correct |
22 ms |
11736 KB |
partial |
43 |
Partially correct |
43 ms |
11720 KB |
partial |
44 |
Partially correct |
18 ms |
11436 KB |
partial |
45 |
Partially correct |
17 ms |
11352 KB |
partial |
46 |
Partially correct |
19 ms |
11540 KB |
partial |
47 |
Partially correct |
17 ms |
11356 KB |
partial |
48 |
Correct |
20 ms |
12492 KB |
ok |
49 |
Partially correct |
19 ms |
14284 KB |
partial |
50 |
Partially correct |
25 ms |
13780 KB |
partial |
51 |
Partially correct |
22 ms |
13600 KB |
partial |
52 |
Partially correct |
22 ms |
15048 KB |
partial |
53 |
Partially correct |
23 ms |
15304 KB |
partial |
54 |
Partially correct |
19 ms |
15124 KB |
partial |
55 |
Partially correct |
21 ms |
14880 KB |
partial |
56 |
Partially correct |
23 ms |
14540 KB |
partial |
57 |
Partially correct |
18 ms |
13316 KB |
partial |
58 |
Partially correct |
21 ms |
13148 KB |
partial |
59 |
Partially correct |
20 ms |
13148 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2396 KB |
ok |
2 |
Correct |
0 ms |
600 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 |
348 KB |
ok |
8 |
Correct |
2 ms |
2652 KB |
ok |
9 |
Correct |
24 ms |
5276 KB |
ok |
10 |
Correct |
197 ms |
49196 KB |
ok |
11 |
Correct |
1 ms |
2392 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
2396 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
2396 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
0 ms |
348 KB |
ok |
26 |
Correct |
0 ms |
348 KB |
ok |
27 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
344 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
348 KB |
ok |
31 |
Correct |
0 ms |
344 KB |
ok |
32 |
Correct |
0 ms |
348 KB |
ok |
33 |
Correct |
0 ms |
348 KB |
ok |
34 |
Correct |
1 ms |
348 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 |
860 KB |
ok |
39 |
Correct |
1 ms |
860 KB |
ok |
40 |
Correct |
1 ms |
856 KB |
ok |
41 |
Correct |
1 ms |
860 KB |
ok |
42 |
Correct |
1 ms |
860 KB |
ok |
43 |
Correct |
0 ms |
860 KB |
ok |
44 |
Correct |
1 ms |
2652 KB |
ok |
45 |
Correct |
1 ms |
860 KB |
ok |
46 |
Correct |
1 ms |
860 KB |
ok |
47 |
Partially correct |
22 ms |
11736 KB |
partial |
48 |
Partially correct |
43 ms |
11720 KB |
partial |
49 |
Partially correct |
18 ms |
11436 KB |
partial |
50 |
Partially correct |
17 ms |
11352 KB |
partial |
51 |
Partially correct |
19 ms |
11540 KB |
partial |
52 |
Partially correct |
17 ms |
11356 KB |
partial |
53 |
Correct |
20 ms |
12492 KB |
ok |
54 |
Partially correct |
19 ms |
14284 KB |
partial |
55 |
Partially correct |
25 ms |
13780 KB |
partial |
56 |
Partially correct |
22 ms |
13600 KB |
partial |
57 |
Partially correct |
22 ms |
15048 KB |
partial |
58 |
Partially correct |
23 ms |
15304 KB |
partial |
59 |
Partially correct |
19 ms |
15124 KB |
partial |
60 |
Partially correct |
21 ms |
14880 KB |
partial |
61 |
Partially correct |
23 ms |
14540 KB |
partial |
62 |
Partially correct |
18 ms |
13316 KB |
partial |
63 |
Partially correct |
21 ms |
13148 KB |
partial |
64 |
Partially correct |
20 ms |
13148 KB |
partial |
65 |
Partially correct |
310 ms |
82080 KB |
partial |
66 |
Partially correct |
412 ms |
100932 KB |
partial |
67 |
Partially correct |
331 ms |
107120 KB |
partial |
68 |
Partially correct |
271 ms |
79060 KB |
partial |
69 |
Partially correct |
251 ms |
79308 KB |
partial |
70 |
Partially correct |
257 ms |
79792 KB |
partial |
71 |
Partially correct |
254 ms |
78892 KB |
partial |
72 |
Partially correct |
286 ms |
78888 KB |
partial |
73 |
Correct |
325 ms |
94580 KB |
ok |
74 |
Correct |
288 ms |
94316 KB |
ok |
75 |
Partially correct |
286 ms |
94312 KB |
partial |
76 |
Partially correct |
369 ms |
86908 KB |
partial |
77 |
Partially correct |
374 ms |
86904 KB |
partial |
78 |
Partially correct |
287 ms |
81552 KB |
partial |
79 |
Partially correct |
321 ms |
108616 KB |
partial |
80 |
Partially correct |
310 ms |
108664 KB |
partial |
81 |
Partially correct |
331 ms |
106836 KB |
partial |
82 |
Partially correct |
314 ms |
102468 KB |
partial |
83 |
Partially correct |
342 ms |
104024 KB |
partial |
84 |
Partially correct |
331 ms |
107592 KB |
partial |
85 |
Partially correct |
325 ms |
108612 KB |
partial |
86 |
Partially correct |
290 ms |
106100 KB |
partial |
87 |
Partially correct |
301 ms |
105556 KB |
partial |
88 |
Partially correct |
294 ms |
97624 KB |
partial |
89 |
Partially correct |
291 ms |
81816 KB |
partial |
90 |
Partially correct |
299 ms |
89212 KB |
partial |
91 |
Partially correct |
279 ms |
84124 KB |
partial |
92 |
Partially correct |
346 ms |
106584 KB |
partial |
93 |
Partially correct |
348 ms |
106840 KB |
partial |
94 |
Partially correct |
330 ms |
107848 KB |
partial |
95 |
Partially correct |
318 ms |
107632 KB |
partial |
96 |
Partially correct |
314 ms |
107592 KB |
partial |
97 |
Partially correct |
314 ms |
107656 KB |
partial |
98 |
Partially correct |
292 ms |
108960 KB |
partial |
99 |
Partially correct |
318 ms |
81056 KB |
partial |
100 |
Partially correct |
248 ms |
78932 KB |
partial |
101 |
Partially correct |
254 ms |
78928 KB |
partial |
102 |
Partially correct |
295 ms |
78928 KB |
partial |
103 |
Partially correct |
258 ms |
79056 KB |
partial |
104 |
Partially correct |
240 ms |
78892 KB |
partial |
105 |
Partially correct |
244 ms |
78928 KB |
partial |
106 |
Partially correct |
261 ms |
78932 KB |
partial |
107 |
Partially correct |
278 ms |
78904 KB |
partial |
108 |
Partially correct |
290 ms |
83368 KB |
partial |
109 |
Partially correct |
279 ms |
83084 KB |
partial |