Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>
inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>
inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

/*maze_version*/
vector<vector<ll>> score;
vector<vector<char>> maze;
ll h, w;
ll dy[24] = {0, 0, 1, -1};
ll dx[24] = {1, -1, 0, 0};


int main(){
    cin>>h>>w;
    ll ch,cw,dh,dw;cin>>ch>>cw>>dh>>dw;
    ch--;cw--;dh--;dw--;

    maze.assign(h,vector<char>(w));
    score.assign(h,vector<ll>(w,INF));
    rep(i,h)rep(j,w) cin>>maze[i][j];

    queue<P> que;
    que.push({ch,cw});
    vector<vector<bool>> visit(h,vector<bool>(w,false));

    score[ch][cw]=0;
    while(que.size()){
        P now=que.front();
        que.pop();
        visit[now.fi][now.se]=true;

        if (maze[now.fi][now.se]=='#') continue;

        bool can_move=false;
        rep(i,4){
            ll ny=now.fi+dy[i],nx=now.se+dx[i];
            if(ny<0 || h<=ny || nx<0 || w<=nx) continue;
            if(visit[ny][nx]==true) continue;
            if(maze[ny][nx]=='#') continue;
            visit[ny][nx]=true;

            score[ny][nx]=score[now.fi][now.se];
            que.push({ny,nx});
            can_move=true;
        }

        if(can_move==false){
            for(ly=-2;ly<=2;ly++)for(lx=-2;lx<=2;lx++){
                if(ly==0 && lx==0) continue;
                
                ll ny = now.fi + ly, nx = now.se + lx;
                if (ny < 0 || h <= ny || nx < 0 || w <= nx)
                    continue;
                if (visit[ny][nx] == true)
                    continue;
                if(maze[ny][nx]=='#') continue;
                visit[ny][nx]=true;
                

                score[ny][nx]=score[now.fi][now.se]+1;
                que.push({ny, nx});
            }
        }
    }

    /*rep(i, h)
    {
        rep(j, w)
        {
            if (score[i][j] != INF)
                cout << score[i][j] << " ";
            else
                cout << -1 << " ";
        }
        cout << endl;
    }*/

    if(score[dh][dw]!=INF) cout<<score[dh][dw]<<endl;
    else cout<<-1<<endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:60:17: error: 'ly' was not declared in this scope; did you mean 'dy'?
   60 |             for(ly=-2;ly<=2;ly++)for(lx=-2;lx<=2;lx++){
      |                 ^~
      |                 dy
a.cc:60:38: error: 'lx' was not declared in this scope; did you mean 'dx'?
   60 |             for(ly=-2;ly<=2;ly++)for(lx=-2;lx<=2;lx++){
      |                                      ^~
      |                                      dx
a.cc:64:42: error: 'nx' was not declared in this scope; did you mean 'ny'?
   64 |                 if (ny < 0 || h <= ny || nx < 0 || w <= nx)
      |                                          ^~
      |                                          ny
a.cc:66:31: error: 'nx' was not declared in this scope; did you mean 'ny'?
   66 |                 if (visit[ny][nx] == true)
      |                               ^~
      |                               ny
a.cc:68:29: error: 'nx' was not declared in this scope; did you mean 'ny'?
   68 |                 if(maze[ny][nx]=='#') continue;
      |                             ^~
      |                             ny
a.cc:69:27: error: 'nx' was not declared in this scope; did you mean 'ny'?
   69 |                 visit[ny][nx]=true;
      |                           ^~
      |                           ny
a.cc:73:25: error: no matching function for call to 'std::queue<std::pair<long long int, long long int> >::push(<brace-enclosed initializer list>)'
   73 |                 que.push({ny, nx});
      |                 ~~~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_queue.h:283:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(const value_type&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::deque<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; value_type = std::pair<long long int, long long int>]'
  283 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:283:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::queue<std::pair<long long int, long long int> >::value_type&' {aka 'const std::pair<long long int, long long int>&'}
  283 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:288:7: note: candidate: 'void std::queue<_Tp, _Sequence>::push(value_type&&) [with _Tp = std::pair<long long int, long long int>; _Sequence = std::deque<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > >; value_type = std::pair<long long int, long long int>]'
  288 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:288:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::queue<std::pair<long long int, long long int> >::value_type&&' {aka 'std::pair<long long int, long long int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~