Is there any time limit,why code is not being submitted,it is giving ans

#include

using namespace std;
int findPool(int mat[][1000],int i,int j,int sum,int n,int m)
{
// cout<<"begin "<<i<<j<<endl;

if(mat[i][j]==0||mat[i][j]==2)
{
    return 0;
}

if(i<0||j<0||i>n||j>m)
{
    return 0;
}

/*  for(int i=0;i<n;i++)
{
    for(int j=0;j<n;j++)
    {
        cout<<mat[i][j];
    }
    cout<<endl;
}*/

//cout<<endl;
mat[i][j]=0;
int a =findPool(mat,i+1,j,sum,n,m);

int b=findPool(mat,i-1,j,sum,n,m);

int c=findPool(mat,i,j+1,sum,n,m);

int d=findPool(mat,i,j-1,sum,n,m);

mat[i][j]=2;
//cout<<a+b+c+d+1<<" returning"<<endl;
return a+b+c+d+1;
}
int main()
{
int mat[1000][1000];
int mat1[1000][1000];
int n,m;
cin>>n;
cin>>m;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>mat[i][j];
mat1[i][j]=mat[i][j];
}
}
int max=-1;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(mat[i][j]==0)
{

        mat[i][j]=1;
        
       // cout<<i<<" "<<j<<"*****int the main****** ";
       int a= findPool(mat,i,j,0,n,m);
      // cout<<a<< "the a is"<<endl;
       for(int k=0;k<n;k++)
       {
           for(int l=0;l<m;l++ )
           {
               mat[k][l]=mat1[k][l];
           }
       }
       if(max<a)
       {
           max=a;
       }
      }
    }
}


 cout<<max;
return 0;

}

Please provide your code in coding blocks IDE.

code shared please check

please ignore the previous one and consider this one https://ide.codingblocks.com/s/191721

What you are doing is simple back tracking, this will need to time out. You need to optimize your code.
First we can use a flood fill algorithm to determine the water cells(black) and their sizes. Then we can take each white cell (there’s no point in changing the colour of a black cell) and see what happens if we choose it. We need to check its black neighbouring cells. We take the shapes of the black neighbours, being careful not to choose the same shape twice, and sum their sizes. The answer is the maximum of these sums plus 11 (for the white chosen cell)

Refer to this code for implementation details.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.