#include <iostream>
#include <complex>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <queue>
#include <map>
#include <stack>
#include <cmath>
#include <cstdint>
#include <cassert>
using namespace std;
const int Max = 3001, Inf = 1e9, TLE = 5e6;
#define ll unsigned long long
int lg[Max], cnt;
struct SPTMIN
{
vector <vector <int>> spt;
int query(int i, int j){
int x = lg[j-i+1];
return min(spt[i][x], spt[j - (1LL << x) + 1][x]);
}
SPTMIN(vector <int> v)
{
int n = v.size();
spt.assign(n + 1, vector <int> (lg[n] + 1, Inf));
for(int j = 0; j < lg[n]+1; j++)
{
for(int i = 0; i < n; i++){
if(j == 0){
spt[i][j] = v[i];
continue;
}
spt[i][j] = spt[i][j-1];
if(i + (1LL << (j-1)) < n) spt[i][j] = min(spt[i][j-1], spt[i + (1LL << (j-1))][j-1]);
}
}
}
};
struct SPTMAX
{
vector <vector <int>> spt;
int query(int i, int j){
int x = lg[j-i+1];
return max(spt[i][x], spt[j - (1LL << x) + 1][x]);
}
SPTMAX(vector <int> v)
{
int n = v.size();
spt.assign(n + 1, vector <int> (lg[n] + 1, 0));
for(int j = 0; j < lg[n]+1; j++)
{
for(int i = 0; i < n; i++){
if(j == 0){
spt[i][j] = v[i];
continue;
}
spt[i][j] = spt[i][j-1];
if(i + (1LL << (j-1)) < n) spt[i][j] = max(spt[i][j-1], spt[i + (1LL << (j-1))][j-1]);
}
}
}
};
int rnd(){
return abs(int(rand() ^ (rand() << 3LL) ^ (rand() << 6LL)));
}
int biggest_stadium(int n, std::vector<std::vector<int>> f)
{
vector <vector<int>> A(n, vector <int> (n, 0)),
B(n, vector <int> (n, 0)),
C(n, vector <int> (n, 0)),
D(n, vector <int> (n, 0)),
T(n, vector <int> (n, 0));
vector <SPTMIN> sp1;
vector <SPTMAX> sp2;
cnt = 0;
for(int i = 1; i <= n; i++){
lg[i] = log2(i);
}
for(int i = 0; i < n; i++)
{
int last = -1;
for(int j = 0; j < n; j++){
if(f[i][j] == 1) last = j;
A[i][j] = last;
}
last = n;
for(int j = n-1; j >= 0; j--){
T[i][j] = last;
if(f[i][j] == 1) {
if(j != n-1 && last == j+1){
T[i][j] = T[i][j+1];
}else T[i][j] = j;
last = j;
}
B[i][j] = last;
}
}
for(int i = 0; i < n; i++)
{
int last = -1;
for(int j = 0; j < n; j++){
if(f[j][i] == 1) last = j;
C[j][i] = last+1;
}
last = n;
for(int j = n-1; j >= 0; j--){
if(f[j][i] == 1) last = j;
D[j][i] = last-1;
}
}
for(int i = 0; i < n; i++)
{
sp1.push_back(SPTMIN(D[i]));
sp2.push_back(SPTMAX(C[i]));
}
//return 0;
//vector <vector<vector<int>>> dp1(n + 1, vector <vector<int>>
// (n + 1, vector <int> (n + 1, -1)));
//vector <vector<vector<int>>> dp2(n + 1, vector <vector<int>>
// (n + 1, vector <int> (n + 1, -1)));
unordered_map <ll, int> dp;
auto F = [&](auto F, int i, int j, int a, int b, int c, int d) -> int
{ cnt++;
long long x = ((ll) b) + (((ll) c) << 11LL) + (((ll) d) << 22LL) + (((ll) j) << 33LL)
+ (((ll) i) << 44LL) + (((ll) a) << 55LL);
if(dp[x] != 0) return dp[x];
dp[x] = (b - a + 1);
if(i != j) dp[x] += (d - c + 1);
int mx = 0;
if(i != 0)
{
for(int k = a; k <= b; k++) if(f[i-1][k] == 0)
{
int l1 = max(A[i-1][k]+1, a), r1 = min(B[i-1][k]-1, b);
int l2 = max(c, l1), r2 = min(d, r1);
int ni = sp2[i].query(l1, r1), d = abs(ni - i) - 1, t = (r1 - l1 + 1);
mx = max(mx, F(F, ni, j, l1, r1, l2, r2) - (r2 - l2 + 1) + d * t);
k = r1;
} else k = T[i-1][k];
}
if(j != n-1)
{
for(int k = c; k <= d; k++) if(f[j+1][k] == 0)
{
int l2 = max(A[j+1][k]+1, c), r2 = min(B[j+1][k]-1, d);
int l1 = max(a, l2), r1 = min(b, r2);
int nj = sp1[j].query(l2, r2), d = abs(nj - j) - 1, t = (r2 - l2 + 1);
mx = max(mx, F(F, i, nj, l1, r1, l2, r2) - (r1 - l1 + 1) + d * t);
k = r2;
} else k = T[j+1][k];
}
return dp[x] = (dp[x] + mx);
};
int ans = 0;
srand(time(NULL));
vector <pair<int, pair<int, int>>> fx;
for(int i = 0; i < n; i++)
{
for(int j = 0; j < n; j++)
{
if(f[i][j] == 1) continue;
int l = A[i][j]+1, r = B[i][j]-1;
int ni = sp2[i].query(l, r);
int nj = sp1[i].query(l, r);
int d = r-l+1, h = (nj - ni + 1);
fx.push_back({ d * h, { i, j }});
}
}
sort(fx.rbegin(), fx.rend());
for(auto& u : fx)
{
int i = u.second.first, j = u.second.second;
if(f[i][j] == 1) continue;
int l = A[i][j]+1, r = B[i][j]-1;
ans = max(ans, F(F, i, i, l, r, l, r));
if(n > 500 && cnt > TLE) {
return ans;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
0 ms |
344 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
3 ms |
2396 KB |
ok |
8 |
Correct |
92 ms |
47036 KB |
ok |
9 |
Correct |
1679 ms |
849284 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
348 KB |
ok |
3 |
Correct |
1 ms |
348 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 |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 ms |
344 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
1 ms |
348 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 |
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 |
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 |
Correct |
1 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 |
348 KB |
ok |
24 |
Correct |
1 ms |
344 KB |
ok |
25 |
Correct |
1 ms |
344 KB |
ok |
26 |
Correct |
0 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 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 |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 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 |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
348 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 |
344 KB |
ok |
27 |
Correct |
1 ms |
344 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
624 KB |
ok |
31 |
Correct |
1 ms |
604 KB |
ok |
32 |
Correct |
1 ms |
348 KB |
ok |
33 |
Correct |
0 ms |
348 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
0 ms |
348 KB |
ok |
37 |
Correct |
1 ms |
348 KB |
ok |
38 |
Correct |
0 ms |
348 KB |
ok |
39 |
Correct |
0 ms |
348 KB |
ok |
40 |
Correct |
1 ms |
348 KB |
ok |
41 |
Correct |
1 ms |
604 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 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 |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
1 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 |
14 |
Correct |
0 ms |
348 KB |
ok |
15 |
Correct |
0 ms |
348 KB |
ok |
16 |
Correct |
0 ms |
344 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 |
1 ms |
348 KB |
ok |
22 |
Correct |
0 ms |
348 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 |
344 KB |
ok |
27 |
Correct |
1 ms |
344 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
1 ms |
624 KB |
ok |
31 |
Correct |
1 ms |
604 KB |
ok |
32 |
Correct |
1 ms |
348 KB |
ok |
33 |
Correct |
0 ms |
348 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
0 ms |
348 KB |
ok |
36 |
Correct |
0 ms |
348 KB |
ok |
37 |
Correct |
1 ms |
348 KB |
ok |
38 |
Correct |
0 ms |
348 KB |
ok |
39 |
Correct |
0 ms |
348 KB |
ok |
40 |
Correct |
1 ms |
348 KB |
ok |
41 |
Correct |
1 ms |
604 KB |
ok |
42 |
Correct |
226 ms |
58596 KB |
ok |
43 |
Correct |
182 ms |
56256 KB |
ok |
44 |
Correct |
257 ms |
64984 KB |
ok |
45 |
Correct |
265 ms |
64960 KB |
ok |
46 |
Correct |
258 ms |
64656 KB |
ok |
47 |
Correct |
80 ms |
46280 KB |
ok |
48 |
Correct |
94 ms |
48912 KB |
ok |
49 |
Correct |
87 ms |
48832 KB |
ok |
50 |
Correct |
121 ms |
57280 KB |
ok |
51 |
Correct |
135 ms |
55176 KB |
ok |
52 |
Correct |
68 ms |
44496 KB |
ok |
53 |
Correct |
52 ms |
43288 KB |
ok |
54 |
Correct |
69 ms |
44372 KB |
ok |
55 |
Correct |
80 ms |
45772 KB |
ok |
56 |
Correct |
67 ms |
44476 KB |
ok |
57 |
Correct |
120 ms |
55232 KB |
ok |
58 |
Correct |
123 ms |
55232 KB |
ok |
59 |
Correct |
130 ms |
55232 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
ok |
2 |
Correct |
0 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 |
0 ms |
344 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Correct |
3 ms |
2396 KB |
ok |
9 |
Correct |
92 ms |
47036 KB |
ok |
10 |
Correct |
1679 ms |
849284 KB |
ok |
11 |
Correct |
1 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
1 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 |
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 |
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 |
Correct |
0 ms |
348 KB |
ok |
28 |
Correct |
0 ms |
348 KB |
ok |
29 |
Correct |
0 ms |
348 KB |
ok |
30 |
Correct |
0 ms |
348 KB |
ok |
31 |
Correct |
1 ms |
344 KB |
ok |
32 |
Correct |
1 ms |
344 KB |
ok |
33 |
Correct |
0 ms |
348 KB |
ok |
34 |
Correct |
0 ms |
348 KB |
ok |
35 |
Correct |
1 ms |
624 KB |
ok |
36 |
Correct |
1 ms |
604 KB |
ok |
37 |
Correct |
1 ms |
348 KB |
ok |
38 |
Correct |
0 ms |
348 KB |
ok |
39 |
Correct |
0 ms |
348 KB |
ok |
40 |
Correct |
0 ms |
348 KB |
ok |
41 |
Correct |
0 ms |
348 KB |
ok |
42 |
Correct |
1 ms |
348 KB |
ok |
43 |
Correct |
0 ms |
348 KB |
ok |
44 |
Correct |
0 ms |
348 KB |
ok |
45 |
Correct |
1 ms |
348 KB |
ok |
46 |
Correct |
1 ms |
604 KB |
ok |
47 |
Correct |
226 ms |
58596 KB |
ok |
48 |
Correct |
182 ms |
56256 KB |
ok |
49 |
Correct |
257 ms |
64984 KB |
ok |
50 |
Correct |
265 ms |
64960 KB |
ok |
51 |
Correct |
258 ms |
64656 KB |
ok |
52 |
Correct |
80 ms |
46280 KB |
ok |
53 |
Correct |
94 ms |
48912 KB |
ok |
54 |
Correct |
87 ms |
48832 KB |
ok |
55 |
Correct |
121 ms |
57280 KB |
ok |
56 |
Correct |
135 ms |
55176 KB |
ok |
57 |
Correct |
68 ms |
44496 KB |
ok |
58 |
Correct |
52 ms |
43288 KB |
ok |
59 |
Correct |
69 ms |
44372 KB |
ok |
60 |
Correct |
80 ms |
45772 KB |
ok |
61 |
Correct |
67 ms |
44476 KB |
ok |
62 |
Correct |
120 ms |
55232 KB |
ok |
63 |
Correct |
123 ms |
55232 KB |
ok |
64 |
Correct |
130 ms |
55232 KB |
ok |
65 |
Correct |
3111 ms |
936820 KB |
ok |
66 |
Correct |
1831 ms |
867176 KB |
ok |
67 |
Correct |
1175 ms |
824896 KB |
ok |
68 |
Correct |
2840 ms |
939360 KB |
ok |
69 |
Correct |
2955 ms |
942356 KB |
ok |
70 |
Correct |
2996 ms |
941772 KB |
ok |
71 |
Correct |
2713 ms |
932000 KB |
ok |
72 |
Correct |
1380 ms |
858016 KB |
ok |
73 |
Correct |
1998 ms |
879600 KB |
ok |
74 |
Correct |
2162 ms |
903536 KB |
ok |
75 |
Correct |
2268 ms |
879268 KB |
ok |
76 |
Correct |
1591 ms |
930960 KB |
ok |
77 |
Correct |
1619 ms |
930324 KB |
ok |
78 |
Partially correct |
1940 ms |
923504 KB |
partial |
79 |
Correct |
1049 ms |
812220 KB |
ok |
80 |
Correct |
1041 ms |
812568 KB |
ok |
81 |
Correct |
1237 ms |
825932 KB |
ok |
82 |
Correct |
1750 ms |
858564 KB |
ok |
83 |
Correct |
1773 ms |
850172 KB |
ok |
84 |
Correct |
1049 ms |
814476 KB |
ok |
85 |
Correct |
965 ms |
807312 KB |
ok |
86 |
Correct |
1146 ms |
825776 KB |
ok |
87 |
Correct |
1174 ms |
827900 KB |
ok |
88 |
Correct |
1286 ms |
833348 KB |
ok |
89 |
Correct |
1285 ms |
850868 KB |
ok |
90 |
Correct |
1187 ms |
850600 KB |
ok |
91 |
Correct |
1296 ms |
850608 KB |
ok |
92 |
Correct |
1208 ms |
817848 KB |
ok |
93 |
Correct |
1303 ms |
824248 KB |
ok |
94 |
Correct |
1113 ms |
808060 KB |
ok |
95 |
Correct |
1026 ms |
807588 KB |
ok |
96 |
Correct |
1038 ms |
806584 KB |
ok |
97 |
Correct |
983 ms |
807368 KB |
ok |
98 |
Correct |
932 ms |
803016 KB |
ok |
99 |
Correct |
2596 ms |
925748 KB |
ok |
100 |
Partially correct |
1734 ms |
928156 KB |
partial |
101 |
Partially correct |
1643 ms |
903276 KB |
partial |
102 |
Partially correct |
1781 ms |
926880 KB |
partial |
103 |
Partially correct |
1756 ms |
926620 KB |
partial |
104 |
Partially correct |
1766 ms |
927696 KB |
partial |
105 |
Partially correct |
1846 ms |
927136 KB |
partial |
106 |
Partially correct |
1847 ms |
926684 KB |
partial |
107 |
Partially correct |
1944 ms |
927392 KB |
partial |
108 |
Correct |
2151 ms |
921252 KB |
ok |
109 |
Correct |
2243 ms |
924256 KB |
ok |