Language: C++

//Think simple yet elegant.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=105;
const ll mod=1e9+7;

int dx[]={-2,-2,-2,-1,-1,-2,-2,-1,-1,0,0,2,2,2,1,1,2,2,1,1};
int dy[]={0,-1,-2,-1,-2,1,2,1,2,-2,2,0,1,2,1,2,-1,-2,-1,2};
int dxx[]={1,0,-1,0};
int dyy[]={0,1,0,-1};

bool chk(int x,int y,int h,int w){
	if(x<0 || x>=h || y<0 || y>=w)
		return false;
	return true;
}
int main(){
	fast;
	int h,w,i,j,k,sx,sy,desx,desy;
	cin>>h>>w>>sx>>sy>>desx>>desy;
	--sx,--sy,--desx,--desy;
	char gr[h][w];
	for(i=0;i<h;i++){
		for(j=0;j<w;j++)
			cin>>gr[i][j];
	}
	vector<vector<int>> dis(h,vector<int>(w,1e9));
	vector<vector<bool>> vis(h,vector<bool>(w,false));
	queue<pi> q;
	q.push({sx,sy});
	vis[sx][sy]=true;
	dis[sx][sy]=0;
	while(!q.empty()){
		pi v=q.front();
		int x=v.ff;
		int y=v.ss;
		//cout<<x<<" "<<y<<endl;
		if(x==desx && y==desy){
			cout<<dis[desx][desy];
			return 0;
		}
		q.pop();
		for(i=0;i<4;i++){
			if(chk(x+dxx[i],y+dyy[i],h,w) && !vis[x+dxx[i]][y+dyy[i]] && gr[x+dxx[i]][y+dyy[i]]!='#'){
				//cout<<x+dxx[i]<<" "<<y+dyy[i]<<" "<<gr[x+dxx[i]][y+dyy[i]]<<endl;
				vis[x+dxx[i]][y+dyy[i]]=true;
				dis[x+dxx[i]][y+dyy[i]]=dis[x][y];
				q.push({x+dxx[i],y+dyy[i]});
			}
			else if(chk(x+dxx[i],y+dyy[i],h,w) && vis[x+dxx[i]][y+dyy[i]]){
				dis[x+dxx[i]][y+dyy[i]]=min(dis[x+dxx[i]][y+dyy[i]],dis[x][y]);
			}
		}
		//cout<<"hey"<<endl;
		for(i=0;i<20;++i){
			//cout<<x+dx[i]<<" "<<y+dy[i]<<endl;
			if(chk(x+dx[i],y+dy[i],h,w) && !vis[x+dx[i]][y+dy[i]] && gr[x+dx[i]][y+dy[i]]!='#'){
				//cout<<x+dx[i]<<" "<<y+dy[i]<<" "<<gr[x+dx[i]][y+dy[i]]<<endl;
				vis[x+dx[i]][y+dy[i]]=true;
				dis[x+dx[i]][y+dy[i]]=dis[x][y]+1;
				q.push({x+dx[i],y+dy[i]});
			}
			else if(chk(x+dx[i],y+dy[i],h,w) && vis[x+dx[i]][y+dy[i]]){
				dis[x+dx[i]][y+dy[i]]=min(dis[x+dx[i]][y+dy[i]],dis[x][y]+1);
			}
		}
		
	}
	cout<<-1<<endl;
	
}

Compiler output:
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:7:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_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 = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~