This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define vll vector<ll>
#define pb push_back
int biggest_stadium(int n, std::vector<std::vector<int>> grid)
{
vector<pair<int,int>> trees;
int row[n][n],col[n][n];
bool vis[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
row[i][j]=col[i][j]=-1;
if(grid[i][j])
trees.pb({i,j});
}
row[i][n-1]=-1;
for(int j=n-2;j>=0;j--)
{
if(grid[i][j]!=grid[i][j+1])
{
row[i][j]=j+1;
}
else
{
row[i][j]=row[i][j+1];
}
}
}
for(int j=0;j<n;j++)
{
col[n-1][j]=-1;
for(int i=n-2;i>=0;i--)
{
if(grid[i][j]!=grid[i+1][j])
{
col[i][j]=i+1;
}
else
{
col[i][j]=col[i+1][j];
}
}
}
if(trees.size()==0)
{
return (n*n);
}
else if(trees.size()==1)
{
int x=trees[0].first;
int y=trees[0].second;
return (n*n)-min({(x+1)*(y+1),(n-x)*(y+1),(n-y)*(x+1),(n-y)*(n-x)});
}
else
{
bool can=0;
vector<pair<int,int>> dir={{-1,-1},{-1,1},{1,-1},{1,1}};
for(auto [dx,dy]:dir)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
vis[i][j]=0;
}
}
for(auto [x,y]:trees)
{
for(int i=0;i<=n and (x+(dx*i))<n and 0<=(x+(dx*i));i++)
{
for(int j=0;j<=n and (y+(dy*i))<n and 0<=(y+(dy*i));j++)
{
vis[x][y]=1;
}
}
}
bool pl=1;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(vis[i][j] and grid[i][j]==0)
{
pl=0;
break;
}
}
}
can|=pl;
}
// for(int i=0;i<n;i++)
// {
// for(int j=0;j<n;j++)
// {
// if(grid[i][j]==0)
// {
// if(row[i][j]!=-1 and col[i][row[i][j]]!=-1)
// {
// can=0;
// }
// if(col[i][j]!=-1 and row[col[i][j]][j]!=-1)
// {
// can=0;
// }
// if(row[i][j]!=-1 and row[i][row[i][j]]!=-1)
// {
// can=0;
// }
// if(col[i][j]!=-1 and col[col[i][j]][j]!=-1)
// {
// can=0;
// }
// }
// }
// }
if(can)
{
return (n*n)-(int)trees.size();
}
else
{
return 0;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |