Language: C++

#include <iostream>
#include <algorithm>
using namespace std;

int sousa(int i,int j,char *c,int cnt){
  if(*c[i][j]=='.'){
    if(i>0){
      if(j>0){
        return max({sousa(i-1,j,&c,cnt+1),sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      }else{
        return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i-1,j,&c,cnt+1)});
      }
    }else{
      if(j>0){
        return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      }else{
        return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1)});
      }
    }
  }else{
    return cnt;
  }
}
  
        

int main(){
  int h, w;
  cin >> h >> w;
  char c[h][w];
  int i,j;
  for(i=0;i<h;i++) for(j=0;j<w;j++) cin >> c[i][j];
  int ans = 0;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      ans = max(ans,sousa(i,j,&c,0));
    }
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int sousa(int, int, char*, int)':
a.cc:6:11: error: invalid types 'char[int]' for array subscript
    6 |   if(*c[i][j]=='.'){
      |           ^
a.cc:9:33: error: cannot convert 'char**' to 'char*'
    9 |         return max({sousa(i-1,j,&c,cnt+1),sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                 ^~
      |                                 |
      |                                 char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:9:55: error: cannot convert 'char**' to 'char*'
    9 |         return max({sousa(i-1,j,&c,cnt+1),sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                                       ^~
      |                                                       |
      |                                                       char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:9:77: error: cannot convert 'char**' to 'char*'
    9 |         return max({sousa(i-1,j,&c,cnt+1),sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                                                             ^~
      |                                                                             |
      |                                                                             char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:9:99: error: cannot convert 'char**' to 'char*'
    9 |         return max({sousa(i-1,j,&c,cnt+1),sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                                                                                   ^~
      |                                                                                                   |
      |                                                                                                   char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:9:19: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
    9 |         return max({sousa(i-1,j,&c,cnt+1),sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:11:33: error: cannot convert 'char**' to 'char*'
   11 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i-1,j,&c,cnt+1)});
      |                                 ^~
      |                                 |
      |                                 char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:11:55: error: cannot convert 'char**' to 'char*'
   11 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i-1,j,&c,cnt+1)});
      |                                                       ^~
      |                                                       |
      |                                                       char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:11:77: error: cannot convert 'char**' to 'char*'
   11 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i-1,j,&c,cnt+1)});
      |                                                                             ^~
      |                                                                             |
      |                                                                             char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:11:19: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   11 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i-1,j,&c,cnt+1)});
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided
a.cc:15:33: error: cannot convert 'char**' to 'char*'
   15 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                 ^~
      |                                 |
      |                                 char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:15:55: error: cannot convert 'char**' to 'char*'
   15 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                                       ^~
      |                                                       |
      |                                                       char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:15:77: error: cannot convert 'char**' to 'char*'
   15 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                                                                             ^~
      |                                                                             |
      |                                                                             char**
a.cc:5:29: note:   initializing argument 3 of 'int sousa(int, int, char*, int)'
    5 | int sousa(int i,int j,char *c,int cnt){
      |                       ~~~~~~^
a.cc:15:19: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   15 |         return max({sousa(i+1,j,&c,cnt+1),sousa(i,j+1,&c,cnt+1),sousa(i,j-1,&c,cnt+1)});
      |                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~