import java.util.*; public class Main { public static int AC[][]=new int[200][200]; public static boolean square(int i,int j,int b){ int flag=AC[i][j]; for(int x=0;x<b;x++){ for(int y=0;y<b;y++){ if(AC[i+x][j+y]!=flag) return false; } } return true; } public static void main(String[] args) { Scanner sc=new Scanner(System.in); int R=sc.nextInt(); int C=sc.nextInt(); int maxBC=Math.min(R, C);//最大边长不可超过矩形最短边 //传入数组 for(int x=0;x<R;x++){ for(int y=0;y<C;y++){ AC[x][y]=sc.nextInt(); } } int max=0;//正方形最大边长 int b;//正方形边长 for(int x=0;x<R;x++){ for(int y=0;y<C;y++){ for(b=max+1;b<=maxBC;b++){ if(x+b<=R&&y+b<=C){ if(square(x,y,b)) max=b; else continue; } } } } System.out.println(max*max); } } /************************************************************** Problem: 1954 User: admin Language: Java Result: Accepted Time:5378 ms Memory:64064 kb ****************************************************************/