-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMax sized square of 1.cpp
More file actions
69 lines (54 loc) · 1.18 KB
/
Max sized square of 1.cpp
File metadata and controls
69 lines (54 loc) · 1.18 KB
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
65
66
67
68
69
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define p_q priority_queue
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int r,c;
int fun( vector< vector<bool> > &m)
{
int dp[r][c];
int ans = 0;
for(int i=0;i<c;i++)
dp[0][i] = m[0][i];
for(int j=0;j<r;j++)
dp[j][0] = m[j][0];
for(int i=1;i<r;i++)
{
for(int j=1;j<c;j++)
{
if(m[i][j] == 1)
{
dp[i][j] = 1 + min({ dp[i-1][j], dp[i][j-1], dp[i-1][j-1] });
ans = max(ans, dp[i][j]);
}
else
dp[i][j] = 0;
}
}
//cout<<ans<<endl;
return ans;
}
int main()
{
fast_io;
bool x;
cin>>r>>c;
vector< vector<bool> > m;
for(int i=0;i<r;i++)
{
vector<bool> temp(c);
for(int j=0;j<c;j++)
{
cin>>x;
temp.pb(x);
}
m.pb(temp);
}
fun(m);
return 0;
}