#include "soccer.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e3+7;
unordered_map<ll,int>mp;
vector<int>P[LIM], pole;
vector<pair<int,int>>V[LIM*LIM*2];
int lewo[LIM], prawo[LIM], odw[LIM], lst[LIM], dp[LIM*LIM*2], czy[LIM*LIM*2], ile[LIM], akt, ans;
void DFS(int x) {
czy[x]=1;
for(auto i : V[x]) {
if(!czy[i.st]) DFS(i.st);
dp[x]=max(dp[x], dp[i.st]+i.nd);
}
ans=max(ans, dp[x]+pole[x]);
}
ll koduj(pair<pair<int,int>,pair<int,int>>x) {
ll p=(ll)x.st.st;
p*=(ll)LIM;
p+=(ll)x.st.nd;
p*=(ll)LIM;
p+=(ll)x.nd.st;
p*=(ll)LIM;
p+=(ll)x.nd.nd;
return p;
}
int biggest_stadium(int n, vector<vector<int>>T) {
pole.pb(0);
rep(i, n) {
rep(j, n) {
++ile[j];
if(T[i][j]) ile[j]=0;
}
rep(j, n+1) {
P[j].clear();
lewo[j]=prawo[j]=j;
odw[j]=0;
lst[j]=n;
}
rep(j, n) P[ile[j]].pb(j);
for(int j=n; j; --j) for(auto l : P[j]) {
vector<pair<pair<int,int>,pair<int,int>>>A;
int a=l, b=l;
if(l && odw[l-1]) {
A.pb({{lewo[l-1], l-1}, {i, i-lst[l-1]+1}});
a=lewo[l-1];
}
if(l+1<n && odw[l+1]) {
A.pb({{l+1, prawo[l+1]}, {i, i-lst[l+1]+1}});
b=prawo[l+1];
}
pair<pair<int,int>,pair<int,int>>x={{a, b}, {i, i-j+1}};
if(!mp[koduj(x)]) {
mp[koduj(x)]=++akt;
pole.pb((x.st.nd-x.st.st+1)*(x.nd.st-x.nd.nd+1));
}
int k=mp[koduj(x)];
for(auto c : A) V[k].pb({mp[koduj(c)], (c.st.nd-c.st.st+1)*(x.nd.nd-c.nd.nd)});
if(j>1) V[mp[koduj({{a, b}, {i-1, i-j+1}})]].pb({k, b-a+1});
odw[l]=1;
lewo[b]=a;
prawo[a]=b;
lst[a]=lst[b]=j;
}
}
rep(i, n) ile[i]=0;
for(int i=n-1; i>=0; --i) {
rep(j, n) {
++ile[j];
if(T[i][j]) ile[j]=0;
}
rep(j, n+1) {
P[j].clear();
lewo[j]=prawo[j]=j;
odw[j]=0;
lst[j]=n;
}
rep(j, n) P[ile[j]].pb(j);
for(int j=n; j; --j) for(auto l : P[j]) {
vector<pair<pair<int,int>,pair<int,int>>>A;
int a=l, b=l;
if(l && odw[l-1]) {
A.pb({{lewo[l-1], l-1}, {i+lst[l-1]-1, i}});
a=lewo[l-1];
}
if(l+1<n && odw[l+1]) {
A.pb({{l+1, prawo[l+1]}, {i+lst[l+1]-1, i}});
b=prawo[l+1];
}
pair<pair<int,int>,pair<int,int>>x={{a, b}, {i+j-1, i}};
if(!mp[koduj(x)]) {
mp[koduj(x)]=++akt;
pole.pb((x.st.nd-x.st.st+1)*(x.nd.st-x.nd.nd+1));
}
int k=mp[koduj(x)];
for(auto c : A) {
V[k].pb({mp[koduj(c)], (c.st.nd-c.st.st+1)*(c.nd.st-x.nd.st)});
}
odw[l]=1;
lewo[b]=a;
prawo[a]=b;
lst[a]=lst[b]=j;
}
}
rep(i, akt) if(!czy[i+1]) DFS(i+1);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
189520 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
189524 KB |
ok |
2 |
Correct |
78 ms |
189616 KB |
ok |
3 |
Correct |
76 ms |
189520 KB |
ok |
4 |
Correct |
75 ms |
189520 KB |
ok |
5 |
Correct |
78 ms |
189676 KB |
ok |
6 |
Correct |
81 ms |
189712 KB |
ok |
7 |
Correct |
84 ms |
191404 KB |
ok |
8 |
Correct |
193 ms |
235376 KB |
ok |
9 |
Correct |
2470 ms |
926844 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
189524 KB |
ok |
2 |
Correct |
78 ms |
189616 KB |
ok |
3 |
Correct |
71 ms |
189524 KB |
ok |
4 |
Correct |
75 ms |
189520 KB |
ok |
5 |
Correct |
76 ms |
189520 KB |
ok |
6 |
Correct |
73 ms |
189520 KB |
ok |
7 |
Correct |
78 ms |
189520 KB |
ok |
8 |
Correct |
78 ms |
189524 KB |
ok |
9 |
Correct |
83 ms |
189536 KB |
ok |
10 |
Correct |
79 ms |
189648 KB |
ok |
11 |
Correct |
79 ms |
189616 KB |
ok |
12 |
Correct |
83 ms |
189528 KB |
ok |
13 |
Correct |
75 ms |
189520 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
189520 KB |
ok |
2 |
Correct |
84 ms |
189524 KB |
ok |
3 |
Correct |
78 ms |
189616 KB |
ok |
4 |
Correct |
71 ms |
189524 KB |
ok |
5 |
Correct |
75 ms |
189520 KB |
ok |
6 |
Correct |
76 ms |
189520 KB |
ok |
7 |
Correct |
73 ms |
189520 KB |
ok |
8 |
Correct |
78 ms |
189520 KB |
ok |
9 |
Correct |
78 ms |
189524 KB |
ok |
10 |
Correct |
83 ms |
189536 KB |
ok |
11 |
Correct |
79 ms |
189648 KB |
ok |
12 |
Correct |
79 ms |
189616 KB |
ok |
13 |
Correct |
83 ms |
189528 KB |
ok |
14 |
Correct |
75 ms |
189520 KB |
ok |
15 |
Correct |
76 ms |
189452 KB |
ok |
16 |
Correct |
79 ms |
189536 KB |
ok |
17 |
Correct |
75 ms |
189492 KB |
ok |
18 |
Correct |
73 ms |
189588 KB |
ok |
19 |
Correct |
84 ms |
189596 KB |
ok |
20 |
Correct |
77 ms |
189580 KB |
ok |
21 |
Correct |
73 ms |
189564 KB |
ok |
22 |
Correct |
86 ms |
189524 KB |
ok |
23 |
Correct |
83 ms |
189624 KB |
ok |
24 |
Correct |
96 ms |
189612 KB |
ok |
25 |
Correct |
84 ms |
189488 KB |
ok |
26 |
Correct |
78 ms |
189512 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
189520 KB |
ok |
2 |
Correct |
84 ms |
189524 KB |
ok |
3 |
Correct |
78 ms |
189616 KB |
ok |
4 |
Correct |
76 ms |
189520 KB |
ok |
5 |
Correct |
75 ms |
189520 KB |
ok |
6 |
Correct |
71 ms |
189524 KB |
ok |
7 |
Correct |
75 ms |
189520 KB |
ok |
8 |
Correct |
76 ms |
189520 KB |
ok |
9 |
Correct |
73 ms |
189520 KB |
ok |
10 |
Correct |
78 ms |
189520 KB |
ok |
11 |
Correct |
78 ms |
189524 KB |
ok |
12 |
Correct |
83 ms |
189536 KB |
ok |
13 |
Correct |
79 ms |
189648 KB |
ok |
14 |
Correct |
79 ms |
189616 KB |
ok |
15 |
Correct |
83 ms |
189528 KB |
ok |
16 |
Correct |
75 ms |
189520 KB |
ok |
17 |
Correct |
76 ms |
189452 KB |
ok |
18 |
Correct |
79 ms |
189536 KB |
ok |
19 |
Correct |
75 ms |
189492 KB |
ok |
20 |
Correct |
73 ms |
189588 KB |
ok |
21 |
Correct |
84 ms |
189596 KB |
ok |
22 |
Correct |
77 ms |
189580 KB |
ok |
23 |
Correct |
73 ms |
189564 KB |
ok |
24 |
Correct |
86 ms |
189524 KB |
ok |
25 |
Correct |
83 ms |
189624 KB |
ok |
26 |
Correct |
96 ms |
189612 KB |
ok |
27 |
Correct |
84 ms |
189488 KB |
ok |
28 |
Correct |
78 ms |
189512 KB |
ok |
29 |
Correct |
79 ms |
189484 KB |
ok |
30 |
Correct |
77 ms |
189828 KB |
ok |
31 |
Correct |
92 ms |
189780 KB |
ok |
32 |
Correct |
96 ms |
189524 KB |
ok |
33 |
Correct |
78 ms |
189560 KB |
ok |
34 |
Correct |
79 ms |
189560 KB |
ok |
35 |
Correct |
100 ms |
189612 KB |
ok |
36 |
Correct |
97 ms |
189524 KB |
ok |
37 |
Correct |
77 ms |
189704 KB |
ok |
38 |
Correct |
73 ms |
189716 KB |
ok |
39 |
Correct |
89 ms |
189520 KB |
ok |
40 |
Correct |
80 ms |
189596 KB |
ok |
41 |
Correct |
81 ms |
189712 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
189520 KB |
ok |
2 |
Correct |
84 ms |
189524 KB |
ok |
3 |
Correct |
78 ms |
189616 KB |
ok |
4 |
Correct |
76 ms |
189520 KB |
ok |
5 |
Correct |
75 ms |
189520 KB |
ok |
6 |
Correct |
71 ms |
189524 KB |
ok |
7 |
Correct |
75 ms |
189520 KB |
ok |
8 |
Correct |
76 ms |
189520 KB |
ok |
9 |
Correct |
73 ms |
189520 KB |
ok |
10 |
Correct |
78 ms |
189520 KB |
ok |
11 |
Correct |
78 ms |
189524 KB |
ok |
12 |
Correct |
83 ms |
189536 KB |
ok |
13 |
Correct |
79 ms |
189648 KB |
ok |
14 |
Correct |
79 ms |
189616 KB |
ok |
15 |
Correct |
83 ms |
189528 KB |
ok |
16 |
Correct |
75 ms |
189520 KB |
ok |
17 |
Correct |
76 ms |
189452 KB |
ok |
18 |
Correct |
79 ms |
189536 KB |
ok |
19 |
Correct |
75 ms |
189492 KB |
ok |
20 |
Correct |
73 ms |
189588 KB |
ok |
21 |
Correct |
84 ms |
189596 KB |
ok |
22 |
Correct |
77 ms |
189580 KB |
ok |
23 |
Correct |
73 ms |
189564 KB |
ok |
24 |
Correct |
86 ms |
189524 KB |
ok |
25 |
Correct |
83 ms |
189624 KB |
ok |
26 |
Correct |
96 ms |
189612 KB |
ok |
27 |
Correct |
84 ms |
189488 KB |
ok |
28 |
Correct |
78 ms |
189512 KB |
ok |
29 |
Correct |
79 ms |
189484 KB |
ok |
30 |
Correct |
77 ms |
189828 KB |
ok |
31 |
Correct |
92 ms |
189780 KB |
ok |
32 |
Correct |
96 ms |
189524 KB |
ok |
33 |
Correct |
78 ms |
189560 KB |
ok |
34 |
Correct |
79 ms |
189560 KB |
ok |
35 |
Correct |
100 ms |
189612 KB |
ok |
36 |
Correct |
97 ms |
189524 KB |
ok |
37 |
Correct |
77 ms |
189704 KB |
ok |
38 |
Correct |
73 ms |
189716 KB |
ok |
39 |
Correct |
89 ms |
189520 KB |
ok |
40 |
Correct |
80 ms |
189596 KB |
ok |
41 |
Correct |
81 ms |
189712 KB |
ok |
42 |
Correct |
320 ms |
226604 KB |
ok |
43 |
Correct |
259 ms |
221528 KB |
ok |
44 |
Correct |
344 ms |
232492 KB |
ok |
45 |
Correct |
360 ms |
233360 KB |
ok |
46 |
Correct |
324 ms |
230016 KB |
ok |
47 |
Correct |
230 ms |
235284 KB |
ok |
48 |
Correct |
171 ms |
212716 KB |
ok |
49 |
Correct |
176 ms |
214396 KB |
ok |
50 |
Correct |
172 ms |
214768 KB |
ok |
51 |
Correct |
296 ms |
229928 KB |
ok |
52 |
Correct |
107 ms |
197336 KB |
ok |
53 |
Correct |
96 ms |
193988 KB |
ok |
54 |
Correct |
107 ms |
197008 KB |
ok |
55 |
Correct |
113 ms |
201024 KB |
ok |
56 |
Correct |
142 ms |
209696 KB |
ok |
57 |
Correct |
247 ms |
235044 KB |
ok |
58 |
Correct |
258 ms |
234580 KB |
ok |
59 |
Correct |
231 ms |
234532 KB |
ok |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
189520 KB |
ok |
2 |
Correct |
84 ms |
189524 KB |
ok |
3 |
Correct |
78 ms |
189616 KB |
ok |
4 |
Correct |
76 ms |
189520 KB |
ok |
5 |
Correct |
75 ms |
189520 KB |
ok |
6 |
Correct |
78 ms |
189676 KB |
ok |
7 |
Correct |
81 ms |
189712 KB |
ok |
8 |
Correct |
84 ms |
191404 KB |
ok |
9 |
Correct |
193 ms |
235376 KB |
ok |
10 |
Correct |
2470 ms |
926844 KB |
ok |
11 |
Correct |
71 ms |
189524 KB |
ok |
12 |
Correct |
75 ms |
189520 KB |
ok |
13 |
Correct |
76 ms |
189520 KB |
ok |
14 |
Correct |
73 ms |
189520 KB |
ok |
15 |
Correct |
78 ms |
189520 KB |
ok |
16 |
Correct |
78 ms |
189524 KB |
ok |
17 |
Correct |
83 ms |
189536 KB |
ok |
18 |
Correct |
79 ms |
189648 KB |
ok |
19 |
Correct |
79 ms |
189616 KB |
ok |
20 |
Correct |
83 ms |
189528 KB |
ok |
21 |
Correct |
75 ms |
189520 KB |
ok |
22 |
Correct |
76 ms |
189452 KB |
ok |
23 |
Correct |
79 ms |
189536 KB |
ok |
24 |
Correct |
75 ms |
189492 KB |
ok |
25 |
Correct |
73 ms |
189588 KB |
ok |
26 |
Correct |
84 ms |
189596 KB |
ok |
27 |
Correct |
77 ms |
189580 KB |
ok |
28 |
Correct |
73 ms |
189564 KB |
ok |
29 |
Correct |
86 ms |
189524 KB |
ok |
30 |
Correct |
83 ms |
189624 KB |
ok |
31 |
Correct |
96 ms |
189612 KB |
ok |
32 |
Correct |
84 ms |
189488 KB |
ok |
33 |
Correct |
78 ms |
189512 KB |
ok |
34 |
Correct |
79 ms |
189484 KB |
ok |
35 |
Correct |
77 ms |
189828 KB |
ok |
36 |
Correct |
92 ms |
189780 KB |
ok |
37 |
Correct |
96 ms |
189524 KB |
ok |
38 |
Correct |
78 ms |
189560 KB |
ok |
39 |
Correct |
79 ms |
189560 KB |
ok |
40 |
Correct |
100 ms |
189612 KB |
ok |
41 |
Correct |
97 ms |
189524 KB |
ok |
42 |
Correct |
77 ms |
189704 KB |
ok |
43 |
Correct |
73 ms |
189716 KB |
ok |
44 |
Correct |
89 ms |
189520 KB |
ok |
45 |
Correct |
80 ms |
189596 KB |
ok |
46 |
Correct |
81 ms |
189712 KB |
ok |
47 |
Correct |
320 ms |
226604 KB |
ok |
48 |
Correct |
259 ms |
221528 KB |
ok |
49 |
Correct |
344 ms |
232492 KB |
ok |
50 |
Correct |
360 ms |
233360 KB |
ok |
51 |
Correct |
324 ms |
230016 KB |
ok |
52 |
Correct |
230 ms |
235284 KB |
ok |
53 |
Correct |
171 ms |
212716 KB |
ok |
54 |
Correct |
176 ms |
214396 KB |
ok |
55 |
Correct |
172 ms |
214768 KB |
ok |
56 |
Correct |
296 ms |
229928 KB |
ok |
57 |
Correct |
107 ms |
197336 KB |
ok |
58 |
Correct |
96 ms |
193988 KB |
ok |
59 |
Correct |
107 ms |
197008 KB |
ok |
60 |
Correct |
113 ms |
201024 KB |
ok |
61 |
Correct |
142 ms |
209696 KB |
ok |
62 |
Correct |
247 ms |
235044 KB |
ok |
63 |
Correct |
258 ms |
234580 KB |
ok |
64 |
Correct |
231 ms |
234532 KB |
ok |
65 |
Execution timed out |
4586 ms |
725760 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |