#include <bits/stdc++.h>
using namespace std;
bool limites(int N, int i, int j){
return i>=0&&i<N&&j>=0&&j<N;
}
bool comprobar(int N, vector<vector<int>> F){
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(F[i][j]==1||F[i][j]==0){
continue;
}
priority_queue<tuple<int,int,int>,vector<tuple<int,int,int>>,greater<tuple<int,int,int>>>cola;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
vector<vector<int>>dist(N,vector<int>(N,INT_MAX));
dist[i][j]=0;
cola.push({0,i,j});
while(!cola.empty()){
auto[d,x,y]=cola.top();
cola.pop();
for(int dir=0;dir<4;dir++){
int posi=x+dx[dir];
int posj=y+dy[dir];
while(true){
if(!limites(N,posi,posj)||F[posi][posj]==1||F[posi][posj]==0)break;
if((d+1)<dist[posi][posj]){
dist[posi][posj]=d+1;
cola.push({dist[posi][posj],posi,posj});
}
posi+=dx[dir];
posj+=dy[dir];
}
}
}
for(int x=0;x<N;x++){
for(int y=0;y<N;y++){
if(F[x][y]==2&&(dist[x][y]>=3||dist[x][y]==-1)){
return false;
}
}
}
}
}
return true;
}
int biggest_stadium(int N, vector<vector<int>> F){
map<tuple<int,int,int>,bool>libre;
for(int fila=0;fila<N;fila++){
for(int i=0;i<N;i++){
for(int j=i;j<N;j++){
if(i==j){
libre[{fila,i,j}]=!F[fila][j];
}
else{
libre[{fila,i,j}]=(!F[fila][j])&&libre[{fila,i,j-1}];
}
}
}
}
int best=0;
for(int fila=0;fila<N;fila++){
for(int columna=0;columna<N;columna++){
for(int i=0;i<=columna;i++){
for(int j=columna;j<N;j++){
if(libre[{fila,i,j}]){
{
vector<pair<int,int>>almacen;
almacen.push_back({i,j});
int suma=0;
int fil=fila-1;
while(fil>=0&&F[fil][columna]!=1){
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen.back().first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen.back().second){
r++;
}
else{
break;
}
}
almacen.push_back({l,r});
fil--;
}
almacen.push_back({i,j});
fil=fila+1;
int fila_extra=1;
int alm_ant=almacen.size()-1;
while(fil<N&&F[fil][columna]!=1){
if(fila_extra<alm_ant){
/*int l1=almacen[fila_extra].first,r1=almacen[fila_extra].second;
while(true){
if(libre[{fil,l1-1,r1}]&&(l1-1)>=almacen.back().first&&(l1-1)>=almacen[fila_extra-1].first){
l1--;
}
else if(libre[{fil,l1,r1+1}]&&(r1+1)<=almacen.back().second&&(r1+1)<=almacen[fila_extra-1].second){
r1++;
}
else{
break;
}
}
int l2=almacen[fila_extra-1].first,r2=almacen[fila_extra-1].second;
while(true){
if(libre[{fil,l2-1,r2}]&&(l2-1)>=almacen.back().first){
l2--;
}
else if(libre[{fil,l2,r2+1}]&&(r2+1)<=almacen.back().second){
r2++;
}
else{
break;
}
}*/
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen[fila_extra].first&&(l-1)>=almacen.back().first&&(l-1)>=almacen[fila_extra-1].first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen[fila_extra].second&&(r+1)<=almacen.back().second&&(r+1)<=almacen[fila_extra-1].second){
r++;
}
else{
break;
}
}
/*if(libre[{fil,l2,r2}]&&l2>=almacen.back().first&&r2<=almacen.back().second){
almacen.push_back({l2,r2});
}
else if(libre[{fil,l1,r1}]&&l1>=almacen.back().first&&r1<=almacen.back().second&&l1>=almacen[fila_extra-1].first&&r1<=almacen[fila_extra-1].second){
almacen.push_back({l1,r1});
}
else{*/
almacen.push_back({l,r});
//}
}
else if(fila_extra==alm_ant){
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen.back().first&&(l-1)>=almacen[fila_extra-1].first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen.back().second&&(r+1)<=almacen[fila_extra-1].second){
r++;
}
else{
break;
}
}
/*int l2=almacen[fila_extra-1].first,r2=almacen[fila_extra-1].second;
while(true){
if(libre[{fil,l2-1,r2}]&&(l2-1)>=almacen.back().first){
l2--;
}
else if(libre[{fil,l2,r2+1}]&&(r2+1)<=almacen.back().second){
r2++;
}
else{
break;
}
}
if(libre[{fil,l2,r2}]&&l2>=almacen.back().first&&r2<=almacen.back().second){
almacen.push_back({l2,r2});
}
else{*/
almacen.push_back({l,r});
//}
}
else{
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen.back().first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen.back().second){
r++;
}
else{
break;
}
}
almacen.push_back({l,r});
}
fil++;
fila_extra++;
}
for(auto[x,y]:almacen){
suma+=(y-x+1);
}
suma-=(j-i+1);
vector<vector<int>>grid=F;
int cnt=0;
fil=fila;
while(fil>=0&&F[fil][columna]!=1){
for(int y=almacen[cnt].first;y<=almacen[cnt].second;y++){
grid[fil][y]=2;
}
fil--;
cnt++;
}
fil=fila;
while(fil<N&&F[fil][columna]!=1){
for(int y=almacen[cnt].first;y<=almacen[cnt].second;y++){
grid[fil][y]=2;
}
fil++;
cnt++;
}
if(comprobar(N,grid)){
best=max(suma,best);
}
}
{
vector<pair<int,int>>almacen;
almacen.push_back({i,j});
int suma=0;
int fil=fila+1;
while(fil<N&&F[fil][columna]!=1){
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen.back().first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen.back().second){
r++;
}
else{
break;
}
}
almacen.push_back({l,r});
fil++;
}
almacen.push_back({i,j});
fil=fila-1;
int fila_extra=1;
int alm_ant=almacen.size()-1;
while(fil>=0&&F[fil][columna]!=1){
if(fila_extra<alm_ant){
/*int l1=almacen[fila_extra].first,r1=almacen[fila_extra].second;
while(true){
if(libre[{fil,l1-1,r1}]&&(l1-1)>=almacen.back().first&&(l1-1)>=almacen[fila_extra-1].first){
l1--;
}
else if(libre[{fil,l1,r1+1}]&&(r1+1)<=almacen.back().second&&(r1+1)<=almacen[fila_extra-1].second){
r1++;
}
else{
break;
}
}
int l2=almacen[fila_extra-1].first,r2=almacen[fila_extra-1].second;
while(true){
if(libre[{fil,l2-1,r2}]&&(l2-1)>=almacen.back().first){
l2--;
}
else if(libre[{fil,l2,r2+1}]&&(r2+1)<=almacen.back().second){
r2++;
}
else{
break;
}
}*/
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen[fila_extra].first&&(l-1)>=almacen.back().first&&(l-1)>=almacen[fila_extra-1].first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen[fila_extra].second&&(r+1)<=almacen.back().second&&(r+1)<=almacen[fila_extra-1].second){
r++;
}
else{
break;
}
}
/*if(libre[{fil,l2,r2}]&&l2>=almacen.back().first&&r2<=almacen.back().second){
almacen.push_back({l2,r2});
}
else if(libre[{fil,l1,r1}]&&l1>=almacen.back().first&&r1<=almacen.back().second&&l1>=almacen[fila_extra-1].first&&r1<=almacen[fila_extra-1].second){
almacen.push_back({l1,r1});
}
else{*/
almacen.push_back({l,r});
//}
}
else if(fila_extra==alm_ant){
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen.back().first&&(l-1)>=almacen[fila_extra-1].first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen.back().second&&(r+1)<=almacen[fila_extra-1].second){
r++;
}
else{
break;
}
}
/*int l2=almacen[fila_extra-1].first,r2=almacen[fila_extra-1].second;
while(true){
if(libre[{fil,l2-1,r2}]&&(l2-1)>=almacen.back().first){
l2--;
}
else if(libre[{fil,l2,r2+1}]&&(r2+1)<=almacen.back().second){
r2++;
}
else{
break;
}
}
if(libre[{fil,l2,r2}]&&l2>=almacen.back().first&&r2<=almacen.back().second){
almacen.push_back({l2,r2});
}
else{*/
almacen.push_back({l,r});
//}
}
else{
int l=columna,r=columna;
while(true){
if(libre[{fil,l-1,r}]&&(l-1)>=almacen.back().first){
l--;
}
else if(libre[{fil,l,r+1}]&&(r+1)<=almacen.back().second){
r++;
}
else{
break;
}
}
almacen.push_back({l,r});
}
fil--;
fila_extra++;
}
for(auto[x,y]:almacen){
suma+=(y-x+1);
}
suma-=(j-i+1);
vector<vector<int>>grid=F;
int cnt=0;
fil=fila;
while(fil>=0&&F[fil][columna]!=1){
for(int y=almacen[cnt].first;y<=almacen[cnt].second;y++){
grid[fil][y]=2;
}
fil--;
cnt++;
}
fil=fila;
while(fil<N&&F[fil][columna]!=1){
for(int y=almacen[cnt].first;y<=almacen[cnt].second;y++){
grid[fil][y]=2;
}
fil++;
cnt++;
}
if(comprobar(N,grid)){
best=max(suma,best);
}
}
}
else{
continue;
}
}
}
}
}
return best;
}
/*
int main()
{
int N;
cin>>N;
vector<vector<int>> F(N, vector<int>(N));
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cin>>F[i][j];
}
}
int res = biggest_stadium(N, F);
cout<<res<<"\n";
return 0;
}*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
635 ms |
448 KB |
ok |
4 |
Correct |
1515 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Execution timed out |
4520 ms |
32340 KB |
Time limit exceeded |
8 |
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 |
348 KB |
ok |
4 |
Correct |
0 ms |
348 KB |
ok |
5 |
Correct |
0 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
440 KB |
ok |
7 |
Correct |
0 ms |
440 KB |
ok |
8 |
Correct |
1 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 |
348 KB |
ok |
13 |
Correct |
1 ms |
348 KB |
ok |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 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 |
348 KB |
ok |
7 |
Correct |
0 ms |
440 KB |
ok |
8 |
Correct |
0 ms |
440 KB |
ok |
9 |
Correct |
1 ms |
348 KB |
ok |
10 |
Correct |
0 ms |
348 KB |
ok |
11 |
Correct |
1 ms |
348 KB |
ok |
12 |
Correct |
0 ms |
348 KB |
ok |
13 |
Correct |
0 ms |
348 KB |
ok |
14 |
Correct |
1 ms |
348 KB |
ok |
15 |
Correct |
48 ms |
348 KB |
ok |
16 |
Correct |
18 ms |
348 KB |
ok |
17 |
Correct |
3 ms |
344 KB |
ok |
18 |
Correct |
1 ms |
344 KB |
ok |
19 |
Correct |
1 ms |
348 KB |
ok |
20 |
Correct |
1 ms |
348 KB |
ok |
21 |
Correct |
1 ms |
348 KB |
ok |
22 |
Partially correct |
1 ms |
348 KB |
partial |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Correct |
1 ms |
348 KB |
ok |
25 |
Partially correct |
3 ms |
348 KB |
partial |
26 |
Partially correct |
7 ms |
452 KB |
partial |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
635 ms |
448 KB |
ok |
5 |
Correct |
1515 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 |
440 KB |
ok |
10 |
Correct |
0 ms |
440 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 |
1 ms |
348 KB |
ok |
17 |
Correct |
48 ms |
348 KB |
ok |
18 |
Correct |
18 ms |
348 KB |
ok |
19 |
Correct |
3 ms |
344 KB |
ok |
20 |
Correct |
1 ms |
344 KB |
ok |
21 |
Correct |
1 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
348 KB |
ok |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Partially correct |
1 ms |
348 KB |
partial |
25 |
Correct |
1 ms |
348 KB |
ok |
26 |
Correct |
1 ms |
348 KB |
ok |
27 |
Partially correct |
3 ms |
348 KB |
partial |
28 |
Partially correct |
7 ms |
452 KB |
partial |
29 |
Partially correct |
5 ms |
348 KB |
partial |
30 |
Execution timed out |
4587 ms |
1324 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
635 ms |
448 KB |
ok |
5 |
Correct |
1515 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 |
440 KB |
ok |
10 |
Correct |
0 ms |
440 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 |
1 ms |
348 KB |
ok |
17 |
Correct |
48 ms |
348 KB |
ok |
18 |
Correct |
18 ms |
348 KB |
ok |
19 |
Correct |
3 ms |
344 KB |
ok |
20 |
Correct |
1 ms |
344 KB |
ok |
21 |
Correct |
1 ms |
348 KB |
ok |
22 |
Correct |
1 ms |
348 KB |
ok |
23 |
Correct |
1 ms |
348 KB |
ok |
24 |
Partially correct |
1 ms |
348 KB |
partial |
25 |
Correct |
1 ms |
348 KB |
ok |
26 |
Correct |
1 ms |
348 KB |
ok |
27 |
Partially correct |
3 ms |
348 KB |
partial |
28 |
Partially correct |
7 ms |
452 KB |
partial |
29 |
Partially correct |
5 ms |
348 KB |
partial |
30 |
Execution timed out |
4587 ms |
1324 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
348 KB |
ok |
2 |
Correct |
1 ms |
348 KB |
ok |
3 |
Correct |
0 ms |
348 KB |
ok |
4 |
Correct |
635 ms |
448 KB |
ok |
5 |
Correct |
1515 ms |
348 KB |
ok |
6 |
Correct |
0 ms |
348 KB |
ok |
7 |
Correct |
0 ms |
348 KB |
ok |
8 |
Execution timed out |
4520 ms |
32340 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |