Very simple one


#1
int min(int a,int b,int c){
   return min(a,min(b,c));
}
int Solution::solve(vector<vector<int> > &A) {
   int n=A.size();
   int m=A[0].size();
   int mat[n+1][m+1]={0};
   int one=0;
   for(int i=0;i<n;i++){
       if(A[i][0]==1)
           one=1;
       mat[i][0]=A[i][0];
   }
   
   for(int i=0;i<m;i++){
       if(A[0][i]==1)one=1;
       mat[0][i]=A[0][i];
   }
   int val=0;
   if(one)
   val=1;
   for(int i=1;i<n;i++){
       for(int j=1;j<m;j++){
           if(A[i][j]==1){
               if(A[i-1][j-1]==1 and A[i-1][j]==1 and A[i][j-1]==1){
                   mat[i][j]=1+min(mat[i-1][j-1],mat[i][j-1],mat[i-1][j]);
                   val=max(mat[i][j],val);
                   //cout<<i<<" "<<j<<" "<<val<<endl;
               }
               else{
                   mat[i][j]=1;
                   val=max(mat[i][j],val);
               }
           }
       }
   }
    return val*val;
}