fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void checkforZeros(int **mat,int i,int j,vector<pair<int,int>> &t1, int n)
  6. {
  7. if(i<0 || j<0 || i>=n || j>=n || mat[i][j]!=0)
  8. return ;
  9.  
  10.  
  11. mat[i][j]=1;
  12. t1.push_back(pair<int,int>(i,j));
  13.  
  14.  
  15. checkforZeros(mat,i+1,j,t1,n);
  16. checkforZeros(mat,i,j+1,t1,n);
  17. checkforZeros(mat,i+1,j+1,t1,n);
  18. }
  19.  
  20.  
  21. int main()
  22. {
  23. int n;
  24. cin>>n;
  25. int **mat;
  26. mat=new int*[n];
  27. for(int i=0;i<n;i++)
  28. {
  29. mat[i]=new int[n];
  30. }
  31.  
  32.  
  33. for(int i=0;i<n;i++)
  34. {
  35. for(int j=0;j<n;j++)
  36. {
  37. cin>>mat[i][j];
  38. }
  39. }
  40.  
  41.  
  42. for(int i=0;i<n;i++)
  43. {
  44. for(int j=0;j<n;j++)
  45. {
  46. if(mat[i][j]==0)
  47. {
  48. cout<<i<<" "<<j<<endl;
  49. vector<pair<int,int>> t1;
  50. checkforZeros(mat,i,j,t1,n);
  51. sort(t1.begin(),t1.end());
  52. auto a=t1.back();
  53. cout<<a.first<<" "<<a.second<<endl;
  54. t1.clear();
  55. }
  56. }
  57. }
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 4436KB
stdin
5
1 1 1 1 0
0 0 0 1 0
0 0 0 1 1
1 1 1 1 1 
1 1 1 0 0
stdout
0 4
1 4
1 0
2 2
4 3
4 4