#include <bits/stdc++.h>
using namespace std;
bool dp[4][2005][2005];
/*
let's consider the bottom edge
we must be able to reach all other cells with an up kick then left kick
a rectangle is a valid field because yes
if any two filled positions on same row or col have a tree between them then no
if we fill in all empty spaces and consider that whole square
we see that the trees form either strict decreasing or strict increasing thingies
xx..
xxx.
.xxx
..xx
still bad
consider top-left one
it needs to either have access to all rows or all cols
xxxx
xxxx
.xxx
..xx
now good
xxxx
.xxx
..xx
....
still good
so, one side needs to be completely filled in
if we can solve where the top side is completely full, then rotate 90deg 4 times
xxxx
.xxx
..xx
...x
now, restriction on rest is?
it must be increasing then decreasing section
xxxxxxxx
.xxxxx.x
..xxx..x
...xx..x
let's say we have down[i][j] : how far down we can go from here
for a given row, let's say position k is the local maximum
then we do a greedy on both sides to calculate scores
so O(n^2) per row
so O(n^3) in total
where does this account for something like
x
x
xxxxx
x
x
x
xxx
xxxxx
x
x
I think in addition to the backbone and stalagmites we can have one prong upwards
xxxxx
xxx
xx
x
x
x
xxxxx
xxx
xx
x
i think the prong needs to be above the splitting point, too
otherwise, there's a column we can't reach
what if the local maximum isn't strict? can we have another?
xx
xx
xxxxx
xxx
xxx
xx
yes we can
the stuff on top needs to also have this same pattern though
x
xx
xx
xxxxx
xxx
xxx
xx
like this is fine but it can't go down then up again
x x
xxx
xxx
xxxxx
xxx
xxx
xxx
we need to iterate through the heights of the local max now
so now it's O(n^4)
*/
const int MAXN = 2000;
int down[MAXN][MAXN];
int up[MAXN][MAXN];
int solve(int N, vector<vector<int>> F) {
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
// go as far down as possible in O(n^3)
for (int k=i; k<N; k++) {
if (F[k][j] == 1) break;
down[i][j] = k-i+1;
}
// go as far up as possible in O(n^3)
for (int k=i; k>=0; k--) {
if (F[k][j] == 1) break;
up[i][j] = i-k+1;
}
}
}
int best = 0;
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
if (F[i][j] == 1) continue;
// choose position (i, j) as the splitting point on row i
for (int h=1; h<=down[i][j]; h++) {
// choose its height down below to be h
int ans = h;
// go left on bottom
int L = j;
{
int curr = h;
bool flag = true;
for (int k=j-1; k>=0; k--) {
if (F[i][k] == 1) break;
if (down[i][k] >= curr && flag) L = k;
if (down[i][k] < curr) flag = false;
curr = min(curr, down[i][k]);
ans += curr;
}
}
// go right on bottom
int R = j;
{
int curr = h;
bool flag = true;
for (int k=j+1; k<N; k++) {
if (F[i][k] == 1) break;
if (down[i][k] >= curr && flag) R = k;
if (down[i][k] < curr) flag = false;
curr = min(curr, down[i][k]);
ans += curr;
}
}
// choose splitting point on top to be j2
int best2 = 0;
for (int j2=L; j2<=R; j2++) {
int ans2 = up[i][j] - 1;
// go left on top
{
int curr = up[i][j];
for (int k=j-1; k>=0; k--) {
if (F[i][k] == 1) break;
curr = min(curr, up[i][k]);
ans2 += curr - 1;
}
}
// go right on top
{
int curr = up[i][j];
for (int k=j+1; k<N; k++) {
if (F[i][k] == 1) break;
curr = min(curr, up[i][k]);
ans2 += curr - 1;
}
}
best2 = max(best2, ans2);
}
// ans += best2;
ans += up[i][j] - 1;
best = max(best, ans);
}
}
}
return best;
}
vector<vector<int>> rotate(int N, vector<vector<int>> F) {
vector<vector<int>> G(N, vector<int>(N));
for (int i=0; i<N; i++) {
for (int j=0; j<N; j++) {
G[i][j] = F[N-1-j][i];
}
}
return G;
}
int biggest_stadium(int N, vector<vector<int>> F) {
int best = 0;
for (int i=0; i<4; i++) {
best = max(best, solve(N, F));
F = rotate(N, F);
}
return best;
}
/*
5
0 0 0 0 0
1 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
0 ms |
600 KB |
ok |
5 |
Correct |
1 ms |
348 KB |
ok |
6 |
Correct |
1 ms |
344 KB |
ok |
7 |
Correct |
153 ms |
1420 KB |
ok |
8 |
Execution timed out |
4585 ms |
9300 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
ok |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
600 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 |
0 ms |
348 KB |
ok |
9 |
Correct |
1 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
0 ms |
344 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
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 |
600 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 |
348 KB |
ok |
9 |
Correct |
0 ms |
348 KB |
ok |
10 |
Correct |
1 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 |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
348 KB |
ok |
17 |
Partially correct |
0 ms |
348 KB |
partial |
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 |
0 ms |
348 KB |
ok |
23 |
Correct |
0 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
348 KB |
ok |
25 |
Partially correct |
1 ms |
348 KB |
partial |
26 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
600 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 |
1 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
344 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 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
ok |
27 |
Partially correct |
1 ms |
348 KB |
partial |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
604 KB |
ok |
31 |
Correct |
1 ms |
604 KB |
ok |
32 |
Correct |
1 ms |
600 KB |
ok |
33 |
Correct |
1 ms |
604 KB |
ok |
34 |
Incorrect |
1 ms |
600 KB |
wrong |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
600 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 |
1 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
0 ms |
344 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 |
Partially correct |
0 ms |
348 KB |
partial |
20 |
Correct |
0 ms |
348 KB |
ok |
21 |
Correct |
0 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
ok |
27 |
Partially correct |
1 ms |
348 KB |
partial |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
604 KB |
ok |
31 |
Correct |
1 ms |
604 KB |
ok |
32 |
Correct |
1 ms |
600 KB |
ok |
33 |
Correct |
1 ms |
604 KB |
ok |
34 |
Incorrect |
1 ms |
600 KB |
wrong |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
600 KB |
ok |
6 |
Correct |
1 ms |
348 KB |
ok |
7 |
Correct |
1 ms |
344 KB |
ok |
8 |
Correct |
153 ms |
1420 KB |
ok |
9 |
Execution timed out |
4585 ms |
9300 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |