#include "soccer.h"
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[2001][2001];
typedef pair<int,int> P;
typedef pair<P,P> PP;
map<int,int> mp[2001][2001];
int psum[2001][2001];
int ri[2001][2001];
int ntr[2001][2001];
const long long three=1e12;
const long long two=1e8;
const long long one=1e4;
int query(int u,int d,int l,int r) {
return psum[d][r]-psum[u-1][r]-psum[d][l-1]+psum[u-1][l-1];
}
long long hhash(PP x) {
return x.first.first*three+x.first.second*two+x.second.first*one+x.second.second;
}
PP unhash(long long x) {
PP ret;
ret.second.second=x%(n+1);
x/=n+1;
ret.second.first=x%(n+1);
x/=n+1;
ret.first.second=x%(n+1);
x/=n+1;
ret.first.first=x%(n+1);
return ret;
}
int ans(int l,int r,int u,int d) {
if (mp[l][r].find(u)!=mp[l][r].end()) {
return mp[l][r][u];
}
int now=l;
if (arr[u-1][now]==1) {
now=ntr[u-1][now];
}
int ret=(d-u+1)*(r-l+1);
if (u>1) {
while (now<=r) {
int ll=now;
int rr=min(ri[u-1][now],r);
int uu=u;
int dd=d;
int lo=0;
int hi=u;
int val=psum[u-1][rr]-psum[u-1][ll-1];
while (lo+1<hi) {
int mid=(lo+hi)/2;
if (-psum[mid-1][rr]+psum[mid-1][ll-1]==-val) {
hi=mid;
}
else {
lo=mid;
}
}
uu=hi;
ret=max(ret,ans(ll,rr,uu,dd)+(r-l-rr+ll)*(d-u+1));
now=ntr[u-1][ri[u-1][now]];
}
}
now=l;
if (arr[d+1][now]==1) {
now=ntr[d+1][now];
}
if (d<n) {
while (now<=r) {
int ll=now;
int rr=min(ri[d+1][now],r);
int uu=u;
int dd=d;
int lo=d;
int hi=n+1;
int val=-psum[d][rr]+psum[d][ll-1];
while (lo+1<hi) {
int mid=(lo+hi)/2;
if (psum[mid][rr]-psum[mid][ll-1]==-val) {
lo=mid;
}
else {
hi=mid;
}
}
dd=lo;
ret=max(ret,ans(ll,rr,uu,dd)+(r-l-rr+ll)*(d-u+1));
now=ntr[d+1][ri[d+1][now]];
}
}
return mp[l][r][u]=ret;
}
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++) {
arr[i+1][j+1]=F[i][j];
}
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
psum[i][j]=psum[i-1][j]+psum[i][j-1]-psum[i-1][j-1]+arr[i][j];
}
}
for(int i=1;i<=n;i++) {
int pr=0;
for(int j=1;j<=n;j++) {
if (arr[i][j]==1) {
for(int k=pr+1;k<j;k++) {
ri[i][k]=j-1;
}
pr=j;
}
}
for(int j=pr+1;j<=n;j++) {
ri[i][j]=n;
}
pr=1;
for(int j=1;j<=n;j++) {
if (arr[i][j]==0) {
for(int k=pr;k<j;k++) {
ntr[i][k]=j;
}
pr=j;
}
}
for(int k=pr;k<=n;k++) {
ntr[i][k]=n+1;
}
}
int ret=0;
for(int i=1;i<=n;i++) {
int pr=0;
for(int j=1;j<=n;j++) {
if (arr[i][j]==1) {
if (pr+1<=j-1) {
ret=max(ret,ans(pr+1,j-1,i,i));
}
pr=j;
}
}
if (pr!=n) {
ret=max(ret,ans(pr+1,n,i,i));
}
}
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
188488 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
188500 KB |
ok |
2 |
Correct |
70 ms |
188496 KB |
ok |
3 |
Correct |
78 ms |
188488 KB |
ok |
4 |
Correct |
69 ms |
188508 KB |
ok |
5 |
Correct |
69 ms |
188272 KB |
ok |
6 |
Correct |
73 ms |
188496 KB |
ok |
7 |
Correct |
76 ms |
190288 KB |
ok |
8 |
Correct |
93 ms |
202912 KB |
ok |
9 |
Correct |
314 ms |
290504 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
188500 KB |
ok |
2 |
Correct |
70 ms |
188496 KB |
ok |
3 |
Correct |
71 ms |
188492 KB |
ok |
4 |
Correct |
71 ms |
188400 KB |
ok |
5 |
Correct |
71 ms |
188496 KB |
ok |
6 |
Correct |
71 ms |
188308 KB |
ok |
7 |
Correct |
71 ms |
188312 KB |
ok |
8 |
Correct |
71 ms |
188672 KB |
ok |
9 |
Correct |
80 ms |
188500 KB |
ok |
10 |
Correct |
73 ms |
188488 KB |
ok |
11 |
Correct |
73 ms |
188496 KB |
ok |
12 |
Correct |
72 ms |
188384 KB |
ok |
13 |
Correct |
72 ms |
188500 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
188488 KB |
ok |
2 |
Correct |
72 ms |
188500 KB |
ok |
3 |
Correct |
70 ms |
188496 KB |
ok |
4 |
Correct |
71 ms |
188492 KB |
ok |
5 |
Correct |
71 ms |
188400 KB |
ok |
6 |
Correct |
71 ms |
188496 KB |
ok |
7 |
Correct |
71 ms |
188308 KB |
ok |
8 |
Correct |
71 ms |
188312 KB |
ok |
9 |
Correct |
71 ms |
188672 KB |
ok |
10 |
Correct |
80 ms |
188500 KB |
ok |
11 |
Correct |
73 ms |
188488 KB |
ok |
12 |
Correct |
73 ms |
188496 KB |
ok |
13 |
Correct |
72 ms |
188384 KB |
ok |
14 |
Correct |
72 ms |
188500 KB |
ok |
15 |
Correct |
69 ms |
188496 KB |
ok |
16 |
Correct |
73 ms |
188392 KB |
ok |
17 |
Correct |
70 ms |
188412 KB |
ok |
18 |
Correct |
71 ms |
188488 KB |
ok |
19 |
Correct |
76 ms |
188496 KB |
ok |
20 |
Correct |
80 ms |
188440 KB |
ok |
21 |
Correct |
71 ms |
188496 KB |
ok |
22 |
Correct |
72 ms |
188380 KB |
ok |
23 |
Correct |
71 ms |
188480 KB |
ok |
24 |
Correct |
77 ms |
188500 KB |
ok |
25 |
Correct |
74 ms |
188496 KB |
ok |
26 |
Correct |
70 ms |
188496 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
188488 KB |
ok |
2 |
Correct |
72 ms |
188500 KB |
ok |
3 |
Correct |
70 ms |
188496 KB |
ok |
4 |
Correct |
78 ms |
188488 KB |
ok |
5 |
Correct |
69 ms |
188508 KB |
ok |
6 |
Correct |
71 ms |
188492 KB |
ok |
7 |
Correct |
71 ms |
188400 KB |
ok |
8 |
Correct |
71 ms |
188496 KB |
ok |
9 |
Correct |
71 ms |
188308 KB |
ok |
10 |
Correct |
71 ms |
188312 KB |
ok |
11 |
Correct |
71 ms |
188672 KB |
ok |
12 |
Correct |
80 ms |
188500 KB |
ok |
13 |
Correct |
73 ms |
188488 KB |
ok |
14 |
Correct |
73 ms |
188496 KB |
ok |
15 |
Correct |
72 ms |
188384 KB |
ok |
16 |
Correct |
72 ms |
188500 KB |
ok |
17 |
Correct |
69 ms |
188496 KB |
ok |
18 |
Correct |
73 ms |
188392 KB |
ok |
19 |
Correct |
70 ms |
188412 KB |
ok |
20 |
Correct |
71 ms |
188488 KB |
ok |
21 |
Correct |
76 ms |
188496 KB |
ok |
22 |
Correct |
80 ms |
188440 KB |
ok |
23 |
Correct |
71 ms |
188496 KB |
ok |
24 |
Correct |
72 ms |
188380 KB |
ok |
25 |
Correct |
71 ms |
188480 KB |
ok |
26 |
Correct |
77 ms |
188500 KB |
ok |
27 |
Correct |
74 ms |
188496 KB |
ok |
28 |
Correct |
70 ms |
188496 KB |
ok |
29 |
Correct |
70 ms |
188476 KB |
ok |
30 |
Correct |
76 ms |
189012 KB |
ok |
31 |
Correct |
73 ms |
188928 KB |
ok |
32 |
Correct |
72 ms |
189008 KB |
ok |
33 |
Correct |
70 ms |
188752 KB |
ok |
34 |
Correct |
71 ms |
188752 KB |
ok |
35 |
Correct |
71 ms |
188752 KB |
ok |
36 |
Correct |
70 ms |
188756 KB |
ok |
37 |
Correct |
71 ms |
188756 KB |
ok |
38 |
Correct |
75 ms |
188752 KB |
ok |
39 |
Correct |
72 ms |
188752 KB |
ok |
40 |
Correct |
72 ms |
188756 KB |
ok |
41 |
Correct |
71 ms |
189012 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
188488 KB |
ok |
2 |
Correct |
72 ms |
188500 KB |
ok |
3 |
Correct |
70 ms |
188496 KB |
ok |
4 |
Correct |
78 ms |
188488 KB |
ok |
5 |
Correct |
69 ms |
188508 KB |
ok |
6 |
Correct |
71 ms |
188492 KB |
ok |
7 |
Correct |
71 ms |
188400 KB |
ok |
8 |
Correct |
71 ms |
188496 KB |
ok |
9 |
Correct |
71 ms |
188308 KB |
ok |
10 |
Correct |
71 ms |
188312 KB |
ok |
11 |
Correct |
71 ms |
188672 KB |
ok |
12 |
Correct |
80 ms |
188500 KB |
ok |
13 |
Correct |
73 ms |
188488 KB |
ok |
14 |
Correct |
73 ms |
188496 KB |
ok |
15 |
Correct |
72 ms |
188384 KB |
ok |
16 |
Correct |
72 ms |
188500 KB |
ok |
17 |
Correct |
69 ms |
188496 KB |
ok |
18 |
Correct |
73 ms |
188392 KB |
ok |
19 |
Correct |
70 ms |
188412 KB |
ok |
20 |
Correct |
71 ms |
188488 KB |
ok |
21 |
Correct |
76 ms |
188496 KB |
ok |
22 |
Correct |
80 ms |
188440 KB |
ok |
23 |
Correct |
71 ms |
188496 KB |
ok |
24 |
Correct |
72 ms |
188380 KB |
ok |
25 |
Correct |
71 ms |
188480 KB |
ok |
26 |
Correct |
77 ms |
188500 KB |
ok |
27 |
Correct |
74 ms |
188496 KB |
ok |
28 |
Correct |
70 ms |
188496 KB |
ok |
29 |
Correct |
70 ms |
188476 KB |
ok |
30 |
Correct |
76 ms |
189012 KB |
ok |
31 |
Correct |
73 ms |
188928 KB |
ok |
32 |
Correct |
72 ms |
189008 KB |
ok |
33 |
Correct |
70 ms |
188752 KB |
ok |
34 |
Correct |
71 ms |
188752 KB |
ok |
35 |
Correct |
71 ms |
188752 KB |
ok |
36 |
Correct |
70 ms |
188756 KB |
ok |
37 |
Correct |
71 ms |
188756 KB |
ok |
38 |
Correct |
75 ms |
188752 KB |
ok |
39 |
Correct |
72 ms |
188752 KB |
ok |
40 |
Correct |
72 ms |
188756 KB |
ok |
41 |
Correct |
71 ms |
189012 KB |
ok |
42 |
Correct |
158 ms |
211796 KB |
ok |
43 |
Correct |
153 ms |
210256 KB |
ok |
44 |
Correct |
177 ms |
212820 KB |
ok |
45 |
Correct |
161 ms |
211920 KB |
ok |
46 |
Correct |
178 ms |
212820 KB |
ok |
47 |
Correct |
91 ms |
203092 KB |
ok |
48 |
Correct |
108 ms |
204368 KB |
ok |
49 |
Correct |
105 ms |
204188 KB |
ok |
50 |
Correct |
113 ms |
208724 KB |
ok |
51 |
Correct |
113 ms |
207852 KB |
ok |
52 |
Correct |
101 ms |
201676 KB |
ok |
53 |
Correct |
95 ms |
200532 KB |
ok |
54 |
Correct |
94 ms |
201976 KB |
ok |
55 |
Correct |
106 ms |
203348 KB |
ok |
56 |
Correct |
91 ms |
202064 KB |
ok |
57 |
Correct |
108 ms |
208588 KB |
ok |
58 |
Correct |
111 ms |
209016 KB |
ok |
59 |
Correct |
112 ms |
209708 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
188488 KB |
ok |
2 |
Correct |
72 ms |
188500 KB |
ok |
3 |
Correct |
70 ms |
188496 KB |
ok |
4 |
Correct |
78 ms |
188488 KB |
ok |
5 |
Correct |
69 ms |
188508 KB |
ok |
6 |
Correct |
69 ms |
188272 KB |
ok |
7 |
Correct |
73 ms |
188496 KB |
ok |
8 |
Correct |
76 ms |
190288 KB |
ok |
9 |
Correct |
93 ms |
202912 KB |
ok |
10 |
Correct |
314 ms |
290504 KB |
ok |
11 |
Correct |
71 ms |
188492 KB |
ok |
12 |
Correct |
71 ms |
188400 KB |
ok |
13 |
Correct |
71 ms |
188496 KB |
ok |
14 |
Correct |
71 ms |
188308 KB |
ok |
15 |
Correct |
71 ms |
188312 KB |
ok |
16 |
Correct |
71 ms |
188672 KB |
ok |
17 |
Correct |
80 ms |
188500 KB |
ok |
18 |
Correct |
73 ms |
188488 KB |
ok |
19 |
Correct |
73 ms |
188496 KB |
ok |
20 |
Correct |
72 ms |
188384 KB |
ok |
21 |
Correct |
72 ms |
188500 KB |
ok |
22 |
Correct |
69 ms |
188496 KB |
ok |
23 |
Correct |
73 ms |
188392 KB |
ok |
24 |
Correct |
70 ms |
188412 KB |
ok |
25 |
Correct |
71 ms |
188488 KB |
ok |
26 |
Correct |
76 ms |
188496 KB |
ok |
27 |
Correct |
80 ms |
188440 KB |
ok |
28 |
Correct |
71 ms |
188496 KB |
ok |
29 |
Correct |
72 ms |
188380 KB |
ok |
30 |
Correct |
71 ms |
188480 KB |
ok |
31 |
Correct |
77 ms |
188500 KB |
ok |
32 |
Correct |
74 ms |
188496 KB |
ok |
33 |
Correct |
70 ms |
188496 KB |
ok |
34 |
Correct |
70 ms |
188476 KB |
ok |
35 |
Correct |
76 ms |
189012 KB |
ok |
36 |
Correct |
73 ms |
188928 KB |
ok |
37 |
Correct |
72 ms |
189008 KB |
ok |
38 |
Correct |
70 ms |
188752 KB |
ok |
39 |
Correct |
71 ms |
188752 KB |
ok |
40 |
Correct |
71 ms |
188752 KB |
ok |
41 |
Correct |
70 ms |
188756 KB |
ok |
42 |
Correct |
71 ms |
188756 KB |
ok |
43 |
Correct |
75 ms |
188752 KB |
ok |
44 |
Correct |
72 ms |
188752 KB |
ok |
45 |
Correct |
72 ms |
188756 KB |
ok |
46 |
Correct |
71 ms |
189012 KB |
ok |
47 |
Correct |
158 ms |
211796 KB |
ok |
48 |
Correct |
153 ms |
210256 KB |
ok |
49 |
Correct |
177 ms |
212820 KB |
ok |
50 |
Correct |
161 ms |
211920 KB |
ok |
51 |
Correct |
178 ms |
212820 KB |
ok |
52 |
Correct |
91 ms |
203092 KB |
ok |
53 |
Correct |
108 ms |
204368 KB |
ok |
54 |
Correct |
105 ms |
204188 KB |
ok |
55 |
Correct |
113 ms |
208724 KB |
ok |
56 |
Correct |
113 ms |
207852 KB |
ok |
57 |
Correct |
101 ms |
201676 KB |
ok |
58 |
Correct |
95 ms |
200532 KB |
ok |
59 |
Correct |
94 ms |
201976 KB |
ok |
60 |
Correct |
106 ms |
203348 KB |
ok |
61 |
Correct |
91 ms |
202064 KB |
ok |
62 |
Correct |
108 ms |
208588 KB |
ok |
63 |
Correct |
111 ms |
209016 KB |
ok |
64 |
Correct |
112 ms |
209708 KB |
ok |
65 |
Correct |
2543 ms |
435796 KB |
ok |
66 |
Correct |
832 ms |
336980 KB |
ok |
67 |
Correct |
461 ms |
307512 KB |
ok |
68 |
Correct |
2108 ms |
429652 KB |
ok |
69 |
Correct |
2826 ms |
465488 KB |
ok |
70 |
Correct |
2777 ms |
461376 KB |
ok |
71 |
Correct |
1626 ms |
396368 KB |
ok |
72 |
Correct |
326 ms |
294440 KB |
ok |
73 |
Correct |
809 ms |
321148 KB |
ok |
74 |
Correct |
837 ms |
323072 KB |
ok |
75 |
Correct |
806 ms |
321604 KB |
ok |
76 |
Correct |
902 ms |
384168 KB |
ok |
77 |
Correct |
969 ms |
384336 KB |
ok |
78 |
Correct |
969 ms |
373212 KB |
ok |
79 |
Correct |
353 ms |
297040 KB |
ok |
80 |
Correct |
352 ms |
296784 KB |
ok |
81 |
Correct |
407 ms |
302500 KB |
ok |
82 |
Correct |
516 ms |
319524 KB |
ok |
83 |
Correct |
591 ms |
318032 KB |
ok |
84 |
Correct |
335 ms |
282964 KB |
ok |
85 |
Correct |
296 ms |
277356 KB |
ok |
86 |
Correct |
343 ms |
285356 KB |
ok |
87 |
Correct |
445 ms |
295008 KB |
ok |
88 |
Correct |
451 ms |
297212 KB |
ok |
89 |
Correct |
304 ms |
291412 KB |
ok |
90 |
Correct |
312 ms |
292176 KB |
ok |
91 |
Correct |
327 ms |
292948 KB |
ok |
92 |
Correct |
418 ms |
301744 KB |
ok |
93 |
Correct |
428 ms |
304976 KB |
ok |
94 |
Correct |
347 ms |
294336 KB |
ok |
95 |
Correct |
327 ms |
292260 KB |
ok |
96 |
Correct |
327 ms |
291668 KB |
ok |
97 |
Correct |
315 ms |
291412 KB |
ok |
98 |
Correct |
306 ms |
290144 KB |
ok |
99 |
Correct |
860 ms |
374352 KB |
ok |
100 |
Correct |
851 ms |
384592 KB |
ok |
101 |
Correct |
678 ms |
379760 KB |
ok |
102 |
Correct |
739 ms |
384344 KB |
ok |
103 |
Correct |
956 ms |
393016 KB |
ok |
104 |
Correct |
853 ms |
396568 KB |
ok |
105 |
Correct |
916 ms |
399440 KB |
ok |
106 |
Correct |
1083 ms |
404288 KB |
ok |
107 |
Correct |
1049 ms |
407132 KB |
ok |
108 |
Correct |
763 ms |
344144 KB |
ok |
109 |
Correct |
1014 ms |
361116 KB |
ok |