Language: C++

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

char g[1005][1005];
int d[1005][1005];
int n, m;
int x1, y1, x2, y2;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};


int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif

  scanf("%d%d", &n, &m);
  scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
  x1--;y1--;x2--;y2--;
  for (int i = 0; i < n; i++) {
    scanf("%s", g[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      d[i][j] = 1e9;
    }
  }
  

  queue<pair<int, int>> q;
  d[x1][y1] = 0;
  q.push({x1, y1});

  while (q.size() > 0) {
    queue<pair<int, int>> h;
    while (q.size() > 0) {
      auto p = q.front();
      h.push(p);
      q.pop();
      for (int i = 0; i < 4; i++) {
        int nx = p.first + dx[i], ny = p.second + dy[i];
        if (nx >= 0 && nx < n && ny >= 0 && ny < m && g[nx][ny] == '.' && d[nx][ny] > d[p.first][p.second]) {
          d[nx][ny] = d[p.first][p.second];
          q.push({nx, ny});
        }
      }
    }
    while (h.size() > 0) {
      auto p = h.front();
      h.pop();
      int x = p.first, y = p.second;
      for (int i = -2; i <= 2; i++) {
        for (int j = -2; j <= 2; j++) {
          int nx = x + i, ny = y + j;
          if (nx >= 0 && nx < n && ny >= 0 && ny < m && g[nx][ny] == '.' && d[nx][ny] > d[x][y] + 1) {
            d[nx][ny] = d[x][y] + 1;
            q.push({nx, ny});
          }
        }
      }
    }
  }
  
  if (d[x2][y2] == 1e9) puts("-1");
  else printf("%d\n", d[x2][y2]);

#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Compiler output:
a.cc:25:9: error: 'int y1' redeclared as different kind of entity
   25 | int x1, y1, x2, y2;
      |         ^~
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
                 from /usr/include/stdio.h:28,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:257:1: note: previous declaration 'double y1(double)'
  257 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
a.cc: In function 'int main()':
a.cc:37:8: warning: ISO C++ forbids decrementing a pointer of type 'double (*)(double) noexcept' [-Wpointer-arith]
   37 |   x1--;y1--;x2--;y2--;
      |        ^~
a.cc:37:10: error: lvalue required as decrement operand
   37 |   x1--;y1--;x2--;y2--;
      |          ^~
a.cc:50:8: error: invalid types 'int [1005][double(double) noexcept]' for array subscript
   50 |   d[x1][y1] = 0;
      |        ^
a.cc:51:9: error: no matching function for call to 'std::queue<std::pair<int, int> >::push(<brace-enclosed initializer list>)'
   51 |   q.push({x1, y1});
      |   ~~~~~~^~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:8:
/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<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, 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<int, int> >::value_type&' {aka 'const std::pair<int, 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<int, int>; _Sequence = std::deque<std::pair<int, int>, std::allocator<std::pair<int, int> > >; value_type = std::pair<int, 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<int, int> >::value_type&&' {aka 'std::pair<int, int>&&'}
  288 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~