Language: C++

#include <bits/stdc++.h>
using namespace std;
int check[1005][1005];
int count[1005][1005];
int main(){
    int h,w;
    cin >> h >> w;
    int ch,cw;
    cin >> ch >> cw;
    ch--; cw--;
    int dh,dw;
    cin >> dh >> dw;
    dh--; dw--;
    char c[h][w];
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){
        cin >> c[i][j];
        check[i][j]=-1;
    }
    queue< pair<int,int> > que;
    que.push(make_pair(ch,cw));
    check[ch][cw]=0;
    int x,y;
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
    while(!que.empty()){
        x=que.front().first;
        y=que.front().second;
        for(int i=0;i<4;i++){
            if(x+dx[i]>=0 && x+dx[i]<h){
                if(y+dy[i]>=0 && y+dy[i]<w){
                    if(c[x+dx[i]][y+dy[i]]=='.' && (check[x+dx[i]][y+dy[i]]== -1 || check[x+dx[i]][y+dy[i]]>check[x][y])){
                        count[x+dx[i]][y+dy[i]]++;
                        if(count[x+dx[i]][y+dy[i]]<5)que.push(make_pair(x+dx[i],y+dy[i]));
                        check[x+dx[i]][y+dy[i]]=check[x][y];
                    }
                    else if(c[x+dx[i]][y+dy[i]]=='#'){
                        for(int j=-2;j<3;j++){
                            if(x+j>=0 && x+j<h){
                            for(int k=-2;k<3;k++){
                                if(y+k>=0 && y+k<w){
                                if(c[x+j][y+k]=='.' && (check[x+j][y+k]==-1 || check[x+j][y+k]>(check[x][y]+1))){
                                count[x+j][y+k]++;
                                if(count[x+j][y+k]<5)que.push(make_pair(x+j,y+k));
                                check[x+j][y+k]=check[x][y]+1;                                   
                                }}
                            }
                            }
                        }
                    }                    
                }
            }
        }
        que.pop();
    }
    cout << check[dh][dw];
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:25: error: reference to 'count' is ambiguous
   32 |                         count[x+dx[i]][y+dy[i]]++;
      |                         ^~~~~
In file included from /usr/include/c++/14/algorithm:86,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:4:5: note:                 'int count [1005][1005]'
    4 | int count[1005][1005];
      |     ^~~~~
a.cc:33:28: error: reference to 'count' is ambiguous
   33 |                         if(count[x+dx[i]][y+dy[i]]<5)que.push(make_pair(x+dx[i],y+dy[i]));
      |                            ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:4:5: note:                 'int count [1005][1005]'
    4 | int count[1005][1005];
      |     ^~~~~
a.cc:42:33: error: reference to 'count' is ambiguous
   42 |                                 count[x+j][y+k]++;
      |                                 ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:4:5: note:                 'int count [1005][1005]'
    4 | int count[1005][1005];
      |     ^~~~~
a.cc:43:36: error: reference to 'count' is ambiguous
   43 |                                 if(count[x+j][y+k]<5)que.push(make_pair(x+j,y+k));
      |                                    ^~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:101:1: note: candidates are: 'template<class _ExecutionPolicy, class _ForwardIterator, class _Tp> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, typename std::iterator_traits<_II>::difference_type> std::count(_ExecutionPolicy&&, _ForwardIterator, _ForwardIterator, const _Tp&)'
  101 | count(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~~
/usr/include/c++/14/bits/stl_algo.h:4025:5: note:                 'template<class _IIter, class _Tp> typename std::iterator_traits< <template-parameter-1-1> >::difference_type std::count(_IIter, _IIter, const _Tp&)'
 4025 |     count(_InputIterator __first, _InputIterator __last, const _Tp& __value)
      |     ^~~~~
a.cc:4:5: note:                 'int count [1005][1005]'
    4 | int count[1005][1005];
      |     ^~~~~