Language: C++

#pragma GCC diagnostic error "-std=c++11"
#pragma GCC target("avx")
#pragma GCC optimize(2)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize(3)
#include<bits/stdc++.h>

#define si(a) scanf("%d",&a)
#define sl(a) scanf("%lld",&a)
#define sd(a) scanf("%lf",&a)
#define sc(a) scahf("%c",&a);
#define ss(a) scanf("%s",a)
#define pi(a) printf("%d\n",a)
#define pl(a) printf("%lld\n",a)
#define pc(a) putchar(a)
#define ms(a) memset(a,0,sizeof(a))
#define repi(i, a, b) for(register int i=a;i<=b;++i)
#define repd(i, a, b) for(register int i=a;i>=b;--i)
#define reps(s) for(register int i=head[s];i;i=Next[i])
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pii pair<int,int>
#define mii unordered_map<int,int>
#define msi unordered_map<string,int>
#define lowbit(x) ((x)&(-(x)))
#define ce(i, r) i==r?'\n':' '
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define pr(x) cout<<#x<<": "<<x<<endl
using namespace std;

inline int qr() {
    int f = 0, fu = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-')fu = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        f = (f << 3) + (f << 1) + c - 48;
        c = getchar();
    }
    return f * fu;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int N = 1e3 + 10, M = 1e6 + 10;
char a[N][N];
int d[N][N];
int n, m, sx, sy, tx, ty;

inline bool check(int x, int y) {
    return x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] != '#';
}

inline int bfs() {
    queue<pii > q;
    q.push({sx, sy}), d[sx][sy] = 0;
    while (!q.empty()) {
        pii t = q.front();
        q.pop();
        repi(i, 0, 3) {
            int nx = t.fi + dx[i], ny = t.se + dy[i];
            if (check(nx, ny) && d[nx][ny] > d[t.fi][t.se])
                d[nx][ny] = d[t.fi][t.se], q.push({nx, ny});
        }
        repi(i, max(1, t.fi - 2), min(n, t.fi + 2))repi(j, max(1, max(1, t.se - 2)), min(m, t.se + 2))if (
                        a[i][j] != '#' && d[i][j] > d[t.fi][t.se] + 1)
                    d[i][j] = d[t.fi][t.se] + 1, q.push({i, j});
    }
    return d[tx][ty] == INF ? -1 : d[tx][ty];
}

int main() {
    n = qr(), m = qr();
    sx = qr(), sy = qr();
    tx = qr(), ty = qr();
    memset(d, 0x3f, sizeof(d));
    repi(i, 1, n)ss(a[i] + 1);
    pi(bfs());
    return 0;
}

Compiler output:
a.cc:1:30: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic error "-std=c++11"
      |                              ^~~~~~~~~~~~
a.cc:23:39: warning: bad option '-fwhole-program' to pragma 'optimize' [-Wpragmas]
   23 | #pragma GCC optimize("-fwhole-program")
      |                                       ^
a.cc:30:41: warning: bad option '-fstrict-overflow' to pragma 'optimize' [-Wpragmas]
   30 | #pragma GCC optimize("-fstrict-overflow")
      |                                         ^
a.cc:32:41: warning: bad option '-fcse-skip-blocks' to pragma 'optimize' [-Wpragmas]
   32 | #pragma GCC optimize("-fcse-skip-blocks")
      |                                         ^
a.cc:46:51: warning: bad option '-funsafe-loop-optimizations' to pragma 'optimize' [-Wpragmas]
   46 | #pragma GCC optimize("-funsafe-loop-optimizations")
      |                                                   ^
a.cc:80:15: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
   80 | inline int qr() {
      |               ^
a.cc:80:15: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
a.cc:80:15: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
a.cc:80:15: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
a.cc:101:31: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  101 | inline bool check(int x, int y) {
      |                               ^
a.cc:101:31: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
a.cc:101:31: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
a.cc:101:31: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
a.cc:105:16: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  105 | inline int bfs() {
      |                ^
a.cc:105:16: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
a.cc:105:16: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
a.cc:105:16: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
a.cc: In function 'int bfs()':
a.cc:111:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  111 |         repi(i, 0, 3) {
      |              ^
a.cc:61:40: note: in definition of macro 'repi'
   61 | #define repi(i, a, b) for(register int i=a;i<=b;++i)
      |                                        ^
a.cc:116:14: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  116 |         repi(i, max(1, t.fi - 2), min(n, t.fi + 2))repi(j, max(1, max(1, t.se - 2)), min(m, t.se + 2))if (
      |              ^
a.cc:61:40: note: in definition of macro 'repi'
   61 | #define repi(i, a, b) for(register int i=a;i<=b;++i)
      |                                        ^
a.cc:116:57: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  116 |         repi(i, max(1, t.fi - 2), min(n, t.fi + 2))repi(j, max(1, max(1, t.se - 2)), min(m, t.se + 2))if (
      |                                                         ^
a.cc:61:40: note: in definition of macro 'repi'
   61 | #define repi(i, a, b) for(register int i=a;i<=b;++i)
      |                                        ^
a.cc: At global scope:
a.cc:123:10: warning: bad option '-fwhole-program' to attribute 'optimize' [-Wattributes]
  123 | int main() {
      |          ^
a.cc:123:10: warning: bad option '-fstrict-overflow' to attribute 'optimize' [-Wattributes]
a.cc:123:10: warning: bad option '-fcse-skip-blocks' to attribute 'optimize' [-Wattributes]
a.cc:123:10: warning: bad option '-funsafe-loop-optimizations' to attribute 'optimize' [-Wattributes]
a.cc: In function 'int main()':
a.cc:128:10: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  128 |     repi(i, 1, n)ss(a[i] + 1);
      |          ^
a.cc:61:40: note: in definition of macro 'repi'
   61 | #define repi(i, a, b) for(register int i=a;i<=b;++i)
      |                                        ^
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:50:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int> > >::_Deque_impl::~_Deque_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = std::pair<int, int>]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/deque:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:139:
/usr/include/c++/14/bits/stl_deque.h:542:14: note: called from here
  542 |       struct _Deque_impl
      |              ^~~~~~~~~~~