Language: C++

/*input
4 4
2 2
3 3
....
....
....
....
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 

int arr[100010][100010];

int h;
int w;



bool legal(int x, int y){
	if(x>=1&&x<=h){
		if(y>=1&&y<=w){
			if(arr[x][y]){
				return true;

			}
		}
	}
	return false;
}


int main() {
 	
 	int a;
 	int b;
 	int a1;
 	int b1;
 	cin>>h>>w>>a>>b>>a1>>b1;
 	memset(arr,0,sizeof(arr));
 	rep(i,h){
 		rep(j,w){
 			char g;
 			cin>>g;
 			if(g=='.'){
 				arr[i+1][j+1] = 1;
 			}
 		}
 	}
 	int dx[4] = {-1,1,0,0};
 	int dy[4] = {0,0,-1,1};
 	int dist[h+2][w+2];
 	rep(i,h+2){
 		rep(j,w+2){
 			dist[i][j] = 1000000000;
 		}
 	}
 	dist[a][b] = 0;
 	deque<PII> q;
 	q.push_front({a,b});
 	while(!q.empty()){
 		PII l = q.front();
 		q.pop_front();
 		int x = l.first;
 		int y = l.second;
 		rep(i,4){
 			int curx = x + dx[i];
 			int cury = y + dy[i];
 			if(legal(curx,cury)){
 				if(dist[curx][cury]>dist[x][y]){
 					dist[curx][cury] = dist[x][y];
 					q.push_front({curx,cury});
 				}
 			}
 		}
 		for(int g = x-2;g<=x+2;g++){
 			for(int p=y-2;p<=y+2;p++){
 				if(legal(g,p)){
 					if(dist[g][p]>dist[x][y]+1){
 						dist[g][p]=dist[x][y]+1;
 						q.push_back({g,p});
 					}
 				}
 			}
 		}
 	}
 	if(dist[a1][b1]>10000000){
 		cout<<-1<<endl;
 	}
 	else{
 		cout<<dist[a1][b1]<<endl;	
 	}
 	


 	
}



 


Compiler output:
/tmp/ccyrm5zq.o: in function `legal(int, int)':
a.cc:(.text+0x12): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x23): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccyrm5zq.o
/tmp/ccyrm5zq.o: in function `main':
a.cc:(.text+0x7c): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x98): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x17d): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x18c): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x1db): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x1fa): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x2f1): relocation truncated to fit: R_X86_64_PC32 against symbol `w' defined in .bss section in /tmp/ccyrm5zq.o
a.cc:(.text+0x303): relocation truncated to fit: R_X86_64_PC32 against symbol `h' defined in .bss section in /tmp/ccyrm5zq.o
collect2: error: ld returned 1 exit status