AcWing 1612. 最大正方形——Java代码版
原题链接
中等
作者:
三玖天下第一
,
2021-03-30 15:09:01
,
所有人可见
,
阅读 406
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String[] temp =reader.readLine().split(" ");
int n = Integer.parseInt(temp[0]), m = Integer.parseInt(temp[1]);
int[][] f = new int[n+1][m+1];
int res = 0;
for (int i = 1; i <=n; i++) {
temp = reader.readLine().split(" ");
for (int j = 1; j <=m; j++) {
f[i][j] = Integer.parseInt(temp[j-1]);
if (f[i][j] == 1){
f[i][j] = Math.min(Math.min(f[i-1][j], f[i][j-1]), f[i-1][j-1]) + 1;
res = Math.max(res, f[i][j]);
}
}
}
System.out.println(res*res);
}
}