Title Description
Farmer John wants to build a large square in the bullpen on his square farm. He hated cutting down trees on his farm, looking for a place that allows him to build the bullpen in the open treeless areas. We assume that his farm is divided into N x N squares. The input data includes a list of tree squares. Your task is to calculate and output, on his farm, but can not require cutting down trees to build the largest square bullpen. Cowshed edges must be parallel and horizontal or vertical axis.
EXAMPLE
Consider the following grid, which represents Farmer John's farm, '' squares represent no trees, '#' indicates trees squares
1 2 3 4 5 6 7 8
1 . . . . . . . .
2 . # . . . # . .
3 . . . . . . . .
4 . . . . . . . .
5 . . . . . . . .
6 . . # . . . . .
7 . . . . . . . .
8 . . . . . . . .
The bullpen is the largest 5 x 5, you can build one of the two lower-right corner of the box.
Input Format
The number N (1 <= N <= 1000), the size of the farm, and T (1 <= T <= 10,000) trees checkered: two integers: 1 Line
Lines 2..T + 1: two integers (1 <= integer <= N), there are horizontal and vertical coordinates of the tree grid
Output Format
Only a single line, the maximum edge length of John's bullpen.
#include<queue>
#include<cmath>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e3+5;
int a[N][N],f[N][N];
int main(){
int n,m;
cin>>n>>m;
for(int i=1,x,y;i<=m;i++){
scanf("%d%d",&x,&y);
a[x][y]=1;
}
int ans=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
if(!a[i][j])f[i][j]=min(min(f[i][j-1],f[i-1][j]),f[i-1][j-1])+1;
ans=max(ans,f[i][j]);
}
cout<<ans<<endl;
}