-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlargest_square.cpp
More file actions
39 lines (37 loc) · 781 Bytes
/
largest_square.cpp
File metadata and controls
39 lines (37 loc) · 781 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
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define pb push_back
#define int long long int
#define double long double
#define pi pair<int, int>
#define pii pair<pi, int>
#define fir first
#define sec second
#define MAXN 1001
#define mod 1000000007
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int v[n][n];
int dp[n][n];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> v[i][j];
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
dp[i][j] = v[i][j];
if (i && j && dp[i][j])
dp[i][j] = min({dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1]}) + 1;
ans = max(ans, dp[i][j]);
}
}
cout << ans * ans << endl;
return 0;
}