#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<queue>
#include "soccer.h"
using namespace std;
const int MAX_N=2e3+3;
int a[MAX_N][MAX_N];
int p[MAX_N][MAX_N];
int n;
bool allempty(int x1,int y1,int x2,int y2)
{
int x11=min(x1,x2),x22=max(x1,x2);
int y11=min(y1,y2),y22=max(y1,y2);
x1=x11+1;y1=y11+1;x2=x22+1;y2=y22+1;
if(p[x2][y2]-p[x1-1][y2]-p[x2][y1-1]+p[x1-1][y1-1]==(x2-x1)*(y2-y1))return 1;
return 0;
}
bool reacheable(int x1,int y1,int x2,int y2)
{
if(allempty(x1,y1,x2,y1) && allempty(x2,y1,x2,y2))return 1;
if(allempty(x1,y1,x1,y2) && allempty(x1,y2,x2,y2))return 1;
return 0;
}
bool checkslow()
{
vector<pair<int,int>>cells;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i][j]==0)cells.push_back({i,j});
}
}
for(int i=0;i<cells.size();i++)
{
for(int j=i+1;j<cells.size();j++)
{
if(!reacheable(cells[i].first,cells[i].second,cells[j].first,cells[j].second))return 0;
}
}
return 1;
}
vector<pair<int,int>>intervals;
bool inside(int i,int j)
{
if(intervals[j].first<=intervals[i].first && intervals[j].second>=intervals[i].second)return 1;
return 0;
}
bool check()
{
int hasprev=0,haslast=0;
for(int i=0;i<n;i++)
{
int f=-1,s=-2;
for(int j=0;j<n;j++)
{
if(a[i][j]==0)
{
if(f==-1)f=j;
s=j;
}
}
for(int j=f;j<=s;j++)
{
if(a[i][j])return 0;
}
int hasnow=(f!=-1 ? 1 : 0);
if(hasnow)
{
intervals.push_back({f,s});
if(haslast==0 && hasprev)return 0;
}
haslast=hasnow;
hasprev=max(hasprev,hasnow);
}
for(int i=1;i<intervals.size();i++)
{
if(inside(i-1,i))continue;
for(int j=0;j<i;j++)
{
if(inside(i,j) or inside(j,i))continue;
return 0;
}
for(int j=i+1;j<intervals.size();j++)
{
if(inside(j,i))continue;
return 0;
}
return 1;
}
return 1;
}
int biggest_stadium(int N, std::vector<std::vector<int>> F)
{
n=N;
int empsz=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
a[i][j]=F[i][j];
if(a[i][j]==0)empsz++;
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
p[i][j]=(a[i-1][j-1]==0)+p[i-1][j]+p[i][j-1]-p[i-1][j-1];
}
}
if(checkslow())return empsz;
return -1;
}
| # | 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... |