// 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;
const int oo = 1e9 + 7;
int n;
int A[maxn][maxn];
vector<pii> ls;
int val1[maxn][maxn], val2[maxn][maxn];
pii val[maxn]; int dp[maxn][maxn];
pii valx[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 y) {
for (int x = 0; x < n; x++) {
if (A[x][y] == 1) val[x] = Mp(n, -1);
else val[x] = Mp(val1[x][y], val2[x][y]);
}
int res = 0;
for (int ln = 1; ln <= n; ln++) {
for (int l = 0, r = ln - 1; r < n; l++, r++) {
if (ln == 1) {
valx[l][r] = val[l];
if (valx[l][r].F > valx[l][r].S) dp[l][r] = -oo;
else dp[l][r] = (valx[l][r].S - valx[l][r].F + 1);
}
else {
valx[l][r] = val[l];
valx[l][r].F = max(valx[l][r].F, valx[l + 1][r].F);
valx[l][r].S = min(valx[l][r].S, valx[l + 1][r].S);
if (valx[l][r].F > valx[l][r].S) dp[l][r] = -oo;
else dp[l][r] = (valx[l][r].S - valx[l][r].F + 1) + max(dp[l + 1][r], dp[l][r - 1]);
}
dp[l][r] = max(dp[l][r], -oo);
res = max(res, dp[l][r]);
}
}
return res;
}
int solve() {
int mx = 0;
for (int j = 0; j < n; j++) {
mx = max(mx, get_val(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 <= 500) return solve();
else return check();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
344 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
856 KB |
ok |
8 |
Correct |
14 ms |
5724 KB |
ok |
9 |
Correct |
219 ms |
55348 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
600 KB |
ok |
6 |
Correct |
0 ms |
348 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 |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
344 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Correct |
1 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 |
600 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 |
348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
344 KB |
ok |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
1 ms |
604 KB |
ok |
16 |
Correct |
1 ms |
348 KB |
ok |
17 |
Correct |
0 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
456 KB |
ok |
19 |
Correct |
1 ms |
604 KB |
ok |
20 |
Correct |
0 ms |
604 KB |
ok |
21 |
Correct |
1 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
604 KB |
ok |
25 |
Correct |
0 ms |
344 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
344 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 |
600 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 |
0 ms |
344 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
604 KB |
ok |
18 |
Correct |
1 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
456 KB |
ok |
21 |
Correct |
1 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
344 KB |
ok |
28 |
Correct |
0 ms |
604 KB |
ok |
29 |
Correct |
1 ms |
600 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 |
964 KB |
ok |
35 |
Correct |
1 ms |
856 KB |
ok |
36 |
Correct |
1 ms |
1116 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
1 ms |
856 KB |
ok |
39 |
Correct |
1 ms |
968 KB |
ok |
40 |
Correct |
0 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
860 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
344 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 |
600 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 |
0 ms |
344 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Correct |
1 ms |
604 KB |
ok |
18 |
Correct |
1 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
456 KB |
ok |
21 |
Correct |
1 ms |
604 KB |
ok |
22 |
Correct |
0 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
604 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
0 ms |
604 KB |
ok |
26 |
Correct |
0 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
344 KB |
ok |
28 |
Correct |
0 ms |
604 KB |
ok |
29 |
Correct |
1 ms |
600 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 |
964 KB |
ok |
35 |
Correct |
1 ms |
856 KB |
ok |
36 |
Correct |
1 ms |
1116 KB |
ok |
37 |
Correct |
1 ms |
860 KB |
ok |
38 |
Correct |
1 ms |
856 KB |
ok |
39 |
Correct |
1 ms |
968 KB |
ok |
40 |
Correct |
0 ms |
860 KB |
ok |
41 |
Correct |
1 ms |
860 KB |
ok |
42 |
Correct |
163 ms |
17624 KB |
ok |
43 |
Correct |
172 ms |
17864 KB |
ok |
44 |
Correct |
193 ms |
17412 KB |
ok |
45 |
Correct |
207 ms |
17272 KB |
ok |
46 |
Correct |
173 ms |
17604 KB |
ok |
47 |
Correct |
244 ms |
17244 KB |
ok |
48 |
Correct |
188 ms |
18376 KB |
ok |
49 |
Correct |
193 ms |
18384 KB |
ok |
50 |
Correct |
199 ms |
17872 KB |
ok |
51 |
Correct |
172 ms |
17620 KB |
ok |
52 |
Correct |
166 ms |
19196 KB |
ok |
53 |
Correct |
160 ms |
19336 KB |
ok |
54 |
Correct |
160 ms |
19204 KB |
ok |
55 |
Correct |
171 ms |
18892 KB |
ok |
56 |
Correct |
193 ms |
18668 KB |
ok |
57 |
Correct |
216 ms |
17244 KB |
ok |
58 |
Correct |
213 ms |
17372 KB |
ok |
59 |
Correct |
210 ms |
17436 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
344 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
1 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 ms |
856 KB |
ok |
9 |
Correct |
14 ms |
5724 KB |
ok |
10 |
Correct |
219 ms |
55348 KB |
ok |
11 |
Correct |
0 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
600 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 |
0 ms |
348 KB |
ok |
18 |
Correct |
0 ms |
348 KB |
ok |
19 |
Correct |
0 ms |
348 KB |
ok |
20 |
Correct |
0 ms |
344 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
604 KB |
ok |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Correct |
0 ms |
348 KB |
ok |
25 |
Correct |
0 ms |
456 KB |
ok |
26 |
Correct |
1 ms |
604 KB |
ok |
27 |
Correct |
0 ms |
604 KB |
ok |
28 |
Correct |
1 ms |
604 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
0 ms |
604 KB |
ok |
31 |
Correct |
0 ms |
604 KB |
ok |
32 |
Correct |
0 ms |
344 KB |
ok |
33 |
Correct |
0 ms |
604 KB |
ok |
34 |
Correct |
1 ms |
600 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 |
964 KB |
ok |
40 |
Correct |
1 ms |
856 KB |
ok |
41 |
Correct |
1 ms |
1116 KB |
ok |
42 |
Correct |
1 ms |
860 KB |
ok |
43 |
Correct |
1 ms |
856 KB |
ok |
44 |
Correct |
1 ms |
968 KB |
ok |
45 |
Correct |
0 ms |
860 KB |
ok |
46 |
Correct |
1 ms |
860 KB |
ok |
47 |
Correct |
163 ms |
17624 KB |
ok |
48 |
Correct |
172 ms |
17864 KB |
ok |
49 |
Correct |
193 ms |
17412 KB |
ok |
50 |
Correct |
207 ms |
17272 KB |
ok |
51 |
Correct |
173 ms |
17604 KB |
ok |
52 |
Correct |
244 ms |
17244 KB |
ok |
53 |
Correct |
188 ms |
18376 KB |
ok |
54 |
Correct |
193 ms |
18384 KB |
ok |
55 |
Correct |
199 ms |
17872 KB |
ok |
56 |
Correct |
172 ms |
17620 KB |
ok |
57 |
Correct |
166 ms |
19196 KB |
ok |
58 |
Correct |
160 ms |
19336 KB |
ok |
59 |
Correct |
160 ms |
19204 KB |
ok |
60 |
Correct |
171 ms |
18892 KB |
ok |
61 |
Correct |
193 ms |
18668 KB |
ok |
62 |
Correct |
216 ms |
17244 KB |
ok |
63 |
Correct |
213 ms |
17372 KB |
ok |
64 |
Correct |
210 ms |
17436 KB |
ok |
65 |
Partially correct |
309 ms |
90036 KB |
partial |
66 |
Partially correct |
398 ms |
108660 KB |
partial |
67 |
Partially correct |
344 ms |
115060 KB |
partial |
68 |
Partially correct |
250 ms |
86864 KB |
partial |
69 |
Partially correct |
261 ms |
87240 KB |
partial |
70 |
Partially correct |
262 ms |
87488 KB |
partial |
71 |
Partially correct |
260 ms |
86804 KB |
partial |
72 |
Partially correct |
254 ms |
86612 KB |
partial |
73 |
Correct |
279 ms |
102296 KB |
ok |
74 |
Correct |
286 ms |
102136 KB |
ok |
75 |
Partially correct |
274 ms |
102140 KB |
partial |
76 |
Partially correct |
359 ms |
94632 KB |
partial |
77 |
Partially correct |
395 ms |
94716 KB |
partial |
78 |
Partially correct |
288 ms |
89136 KB |
partial |
79 |
Partially correct |
346 ms |
116352 KB |
partial |
80 |
Partially correct |
314 ms |
116340 KB |
partial |
81 |
Partially correct |
318 ms |
114608 KB |
partial |
82 |
Partially correct |
307 ms |
110196 KB |
partial |
83 |
Partially correct |
339 ms |
111984 KB |
partial |
84 |
Partially correct |
296 ms |
115404 KB |
partial |
85 |
Partially correct |
294 ms |
116336 KB |
partial |
86 |
Partially correct |
351 ms |
113852 KB |
partial |
87 |
Partially correct |
321 ms |
113524 KB |
partial |
88 |
Partially correct |
274 ms |
105616 KB |
partial |
89 |
Partially correct |
260 ms |
89780 KB |
partial |
90 |
Partially correct |
315 ms |
97176 KB |
partial |
91 |
Partially correct |
259 ms |
91776 KB |
partial |
92 |
Partially correct |
336 ms |
114292 KB |
partial |
93 |
Partially correct |
335 ms |
114660 KB |
partial |
94 |
Partially correct |
339 ms |
115824 KB |
partial |
95 |
Partially correct |
319 ms |
115412 KB |
partial |
96 |
Partially correct |
314 ms |
115572 KB |
partial |
97 |
Partially correct |
329 ms |
115568 KB |
partial |
98 |
Partially correct |
317 ms |
116852 KB |
partial |
99 |
Partially correct |
272 ms |
88768 KB |
partial |
100 |
Partially correct |
276 ms |
87040 KB |
partial |
101 |
Partially correct |
253 ms |
86608 KB |
partial |
102 |
Partially correct |
275 ms |
86608 KB |
partial |
103 |
Partially correct |
266 ms |
86868 KB |
partial |
104 |
Partially correct |
247 ms |
86684 KB |
partial |
105 |
Partially correct |
261 ms |
86820 KB |
partial |
106 |
Partially correct |
250 ms |
86864 KB |
partial |
107 |
Partially correct |
246 ms |
86864 KB |
partial |
108 |
Partially correct |
300 ms |
91284 KB |
partial |
109 |
Partially correct |
311 ms |
91120 KB |
partial |