-
Notifications
You must be signed in to change notification settings - Fork 0
/
0.HinhVuongLonNhat.cpp
64 lines (61 loc) · 1 KB
/
0.HinhVuongLonNhat.cpp
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
int min(int a, int b, int c)
{
int t=a<b?a:b;
return t<c?t:c;
}
int main(){
int m, n, d;
scanf("%d%d", &m, &n);
int a[1005][1005], c[1005][1005];
for(int i=0; i<m ; i++)
{
for(int j=0; j<n; j++)
{
scanf("%d", &a[i][j]);
c[i][j]=a[i][j];
}
}
int max=a[0][0];
for(int i=1; i<m; i++)
{
for(int j=1; j<n; j++)
{
if(a[i][j]>0)
{
c[i][j] = min(c[i][j-1], c[i-1][j], c[i-1][j-1])+1;
}
if(c[i][j]>max)
{
max=c[i][j];
}
}
}
for(int i=0; i<m ; i++)
{
for(int j=0; j<n; j++)
{
a[i][j]=1-a[i][j];
c[i][j]=a[i][j];
}
}
for(int i=1; i<m; i++)
{
for(int j=1; j<n; j++)
{
if(a[i][j]>0)
{
c[i][j] = min(c[i][j-1], c[i-1][j], c[i-1][j-1])+1;
}
if(c[i][j]>max)
{
max=c[i][j];
}
}
}
printf("%d", max);
return 0;
}