-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmaxSizeSquare.cpp
More file actions
32 lines (28 loc) · 908 Bytes
/
Copy pathmaxSizeSquare.cpp
File metadata and controls
32 lines (28 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
using namespace std;
const int Nmax = 1001;
bool a[Nmax][Nmax];
int n,m, maxLen[Nmax][Nmax]; //maxLen[i][j] = max. x such as (i -x +1, j-x+1) -> (i,j) full of 1's
//maxLen[i][j] = min(maxLen[i-1][j], maxLen[i][j-1], maxLen[i-1][j-1]) +1 , if a[i][j]=1
// = 0, otherwise
int maxSizeSquare(bool a[][Nmax], int n, int m){ //passing matrices as arguments the size of the first argument is not
// that mandatory, but the second one is mandatory
int ans = 0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
if(a[i][j] == false)
maxLen[i][j] = 0;
else
maxLen[i][j] = min(maxLen[i][j-1] , min(maxLen[i-1][j], maxLen[i-1][j-1])) + 1;
ans = max(ans, maxLen[i][j]);
}
return ans;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++)
for(int j=1;j<m;j++)
cin>>a[i][j];
cout<<maxSizeSquare(a,n,m);
return 0;
}