Language: C++

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

const int N = 1005;

char a[N][N];

struct data {
  int fi, sc, th;
  data() {}
  data(int fi, int sc, int th):
    fi(fi), sc(sc), th(th) {}
};

class cmp {
public:
  bool operator()(data a, data b) {
    return a.th > b.th;
  }
};

void solve() {
  int n, m;
  cin >> n >> m;
  int cx, cy, dx, dy;
  cin >> cx >> cy >> dx >> dy;
  for (int i = 1; i <= n; i++)
  for (int j = 1; j <= m; j++) {
    cin >> a[i][j];
  }
  priority_queue<data, vector<data>, cmp> q;
  q.push(data(cx, cy, 0));
  while (q.size()) {
    int x = q.top().fi, y = q.top().sc, z = q.top().th;
    q.pop();
    if (x < 1 || x > n || y < 1 || y > m) continue;
    if (a[x][y] == '#') continue;
    a[x][y] = '#';
    if (x == dx && y == dy) {
      cout << z << '\n';
      return;
    }
    q.push(data(x - 1, y, z));
    q.push(data(x + 1, y, z));
    q.push(data(x, y - 1, z));
    q.push(data(x, y + 1, z));
    for (int i = -2; i <= 2; i++)
    for (int j = -2; j <= 2; j++) {
      q.push(data(x + i, y + j, z + 1));
    }
  }
  cout << -1 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Compiler output:
a.cc:25:19: error: reference to 'data' is ambiguous
   25 |   bool operator()(data a, data b) {
      |                   ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:16:8: note:                 'struct data'
   16 | struct data {
      |        ^~~~
a.cc:25:19: error: 'data' has not been declared
   25 |   bool operator()(data a, data b) {
      |                   ^~~~
a.cc:25:27: error: reference to 'data' is ambiguous
   25 |   bool operator()(data a, data b) {
      |                           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:16:8: note:                 'struct data'
   16 | struct data {
      |        ^~~~
a.cc:25:27: error: 'data' has not been declared
   25 |   bool operator()(data a, data b) {
      |                           ^~~~
a.cc: In member function 'bool cmp::operator()(int, int)':
a.cc:26:14: error: request for member 'th' in 'a', which is of non-class type 'int'
   26 |     return a.th > b.th;
      |              ^~
a.cc:26:21: error: request for member 'th' in 'b', which is of non-class type 'int'
   26 |     return a.th > b.th;
      |                     ^~
a.cc: In function 'void solve()':
a.cc:39:35: error: template argument 1 is invalid
   39 |   priority_queue<data, vector<data>, cmp> q;
      |                                   ^
a.cc:39:35: error: template argument 2 is invalid
a.cc:39:41: error: template argument 1 is invalid
   39 |   priority_queue<data, vector<data>, cmp> q;
      |                                         ^
a.cc:39:41: error: template argument 2 is invalid
a.cc:40:5: error: request for member 'push' in 'q', which is of non-class type 'int'
   40 |   q.push(data(cx, cy, 0));
      |     ^~~~
a.cc:40:10: error: reference to 'data' is ambiguous
   40 |   q.push(data(cx, cy, 0));
      |          ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:16:8: note:                 'struct data'
   16 | struct data {
      |        ^~~~
a.cc:41:12: error: request for member 'size' in 'q', which is of non-class type 'int'
   41 |   while (q.size()) {
      |            ^~~~
a.cc:42:15: error: request for member 'top' in 'q', which is of non-class type 'int'
   42 |     int x = q.top().fi, y = q.top().sc, z = q.top().th;
      |               ^~~
a.cc:43:7: error: request for member 'pop' in 'q', which is of non-class type 'int'
   43 |     q.pop();
      |       ^~~
a.cc:44:27: error: 'y' was not declared in this scope
   44 |     if (x < 1 || x > n || y < 1 || y > m) continue;
      |                           ^
a.cc:45:14: error: 'y' was not declared in this scope
   45 |     if (a[x][y] == '#') continue;
      |              ^
a.cc:46:10: error: 'y' was not declared in this scope
   46 |     a[x][y] = '#';
      |          ^
a.cc:48:15: error: 'z' was not declared in this scope
   48 |       cout << z << '\n';
      |               ^
a.cc:51:7: error: request for member 'push' in 'q', which is of non-class type 'int'
   51 |     q.push(data(x - 1, y, z));
      |       ^~~~
a.cc:51:12: error: reference to 'data' is ambiguous
   51 |     q.push(data(x - 1, y, z));
      |            ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:16:8: note:                 'struct data'
   16 | struct data {
      |        ^~~~
a.cc:51:27: error: 'z' was not declared in this scope
   51 |     q.push(data(x - 1, y, z));
      |                           ^
a.cc:52:7: error: request for member 'push' in 'q', which is of non-class type 'int'
   52 |     q.push(data(x + 1, y, z));
      |       ^~~~
a.cc:52:12: error: reference to 'data' is ambiguous
   52 |     q.push(data(x + 1, y, z));
      |            ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:16:8: note:                 'struct data'
   16 | struct data {
      |        ^~~~
a.cc:53:7: error: request for member 'push' in 'q', which is of non-class type 'int'
   53 |     q.push(data(x, y - 1, z));
      |       ^~~~
a.cc:53:12: error: reference to 'data' is ambiguous
   53 |     q.push(data(x, y - 1, z));
      |            ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:16:8: note:                 'struct data'
   16 | struct data {
      |        ^~~~
a.cc:54:7: error: request for member 'push' in 'q', which is of non-class type 'int'
   54 |     q.push(data(x, y + 1, z));
      |       ^~~~
a.cc:54:12: error: reference to 'data' is ambiguous
   54 |     q.push(data(x, y + 1, z));
      |            ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: