Language: C++

#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;

int x, y;
int time[51][51][51][51];
char field[51][51];
int dx[] = {
	0, -1, 0, 1
};
int dy[] = {
	1, 0, -1, 0
};
struct twins{
	int x1;
	int y1;
	int x2; 
	int y2;
};

bool can_move(int x1, int y1){
	if(x1 > 0 && x1 <= x && y1 > 0 && y1 <= y){
		if(field[y1][x1] == '0') return true;
		else return false;
	}
	return false;
}

void get_time(int x1, int y1, int x2, int y2){
	twins t0;
	t0.x1 = x1, t0.x2 = x2, t0.y1 = y1, t0.y2 = y2;
	queue<twins> qt;
	qt.push(t0);
	while(!qt.empty()){
		twins t = qt.front(); qt.pop();
		for(int i = 0; i < 4; i++){
			int ay = t.y1 + dy[i];
			int ax = t.x1 + dx[i];
			int by = t.y2 - dy[i];
			int bx = t.x2 - dx[i];
			if(!can_move(ax, ay)){
				ay = t.y1;
				ax = t.x1;
			}
			if(!can_move(bx, by)){
				by = t.y2;
				bx = t.x2;
			}
			if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
				time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
				t0.x1 = ax, t0.x2 = bx, t0.y1 = ay, t0.y2 = by;
				qt.push(t0);
			}
		}
	}
}

int main(){
	int ax, ay, bx, by;
	while(cin >> x >> y && (x || y)){
		int count = 101;
		memset(time, -1, sizeof(time));
		cin >> ax >> ay >> bx >> by;
		for(int i = 1; i <= y; i++){
			for(int j = 1; j <= x; j++){
				cin >> field[i][j];
			}
		}
		time[ay][ax][by][bx] = 0;
		get_time(ax, ay, bx, by);
		for(int i = 1; i <= y; i++){
			for(int j = 1; j <= x; j++){
				if(time[i][j][i][j] >= 0) count = min(count, time[i][j][i][j]);
			}
		}
		if(count == 101) cout << "NA" << endl;
		else cout << count << endl;
	}
	return 0;
}

Compiler output:
a.cc:14:24: error: 'int time [51][51][51][51]' redeclared as different kind of entity
   14 | int time[51][51][51][51];
      |                        ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'void get_time(int, int, int, int)':
a.cc:57:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                   ^
a.cc:57:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                       ^
a.cc:57:43: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                           ^
a.cc:57:47: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                               ^
a.cc:57:49: error: ordered comparison of pointer with integer zero ('time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} and 'int')
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                            ~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:57:63: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                               ^
a.cc:57:67: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                   ^
a.cc:57:71: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                       ^
a.cc:57:75: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                           ^
a.cc:57:88: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                                        ^
a.cc:57:94: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                                              ^
a.cc:57:100: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                                                    ^
a.cc:57:106: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                                                          ^
a.cc:57:108: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |                         if(time[ay][ax][by][bx] < 0 || time[ay][ax][by][bx] > time[t.y1][t.x1][t.y2][t.x2] + 1){
      |                                                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:58:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                        ^
a.cc:58:44: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                            ^
a.cc:58:48: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                ^
a.cc:58:52: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                    ^
a.cc:58:65: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                                 ^
a.cc:58:71: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                                       ^
a.cc:58:77: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                                             ^
a.cc:58:83: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                                                   ^
a.cc:58:85: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:58:54: error: assignment of read-only location '*(time + (((((sizetype)ay) + ((sizetype)ax)) + ((sizetype)by)) + ((sizetype)bx)))'
   58 |                                 time[ay][ax][by][bx] = time[t.y1][t.x1][t.y2][t.x2] + 1;
      |                                 ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:70:41: error: ISO C++ forbids applying 'sizeof' to an expression of function type [-fpermissive]
   70 |                 memset(time, -1, sizeof(time));
      |                                        ~^~~~~
a.cc:70:17: error: 'memset' was not declared in this scope
   70 |                 memset(time, -1, sizeof(time));
      |                 ^~~~~~
a.cc:10:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    9 | #include <map>
  +++ |+#include <cstring>
   10 | using namespace std;
a.cc:77:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   77 |                 time[ay][ax][by][bx] = 0;
      |                        ^
a.cc:77:28: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   77 |                 time[ay][ax][by][bx] = 0;
      |                            ^
a.cc:77:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   77 |                 time[ay][ax][by][bx] = 0;
      |                                ^
a.cc:77:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   77 |                 time[ay][ax][by][bx] = 0;
      |                                    ^
a.cc:77:38: error: assignment of read-only location '*(time + (((((sizetype)ay) + ((sizetype)ax)) + ((sizetype)by)) + ((sizetype)bx)))'
   77 |                 time[ay][ax][by][bx] = 0;
      |                 ~~~~~~~~~~~~~~~~~~~~~^~~
a.cc:81:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   81 |                                 if(time[i][j][i][j] >= 0) count = min(count, time[i][j][i][j]);
      |                                          ^
a.cc:81:45: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   81 |                                 if(time[i][j][i][j] >= 0) count = min(count, time[i][j][i][j]);
      |                                             ^
a.cc:81:48: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   81 |                                 if(time[i][j][i][j] >= 0) count = min(count, time[i][j][i][j]);
      |                                                ^
a.cc:81:51: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   81 |                                 if(time[i][j][i][j] >= 0) count = min(count, time[i][j][i][j]);
      |                                                   ^
a.cc:81:53: error: ordered comparison of pointer with integer zero ('time_t (*)(time_t*) noexcept' {aka 'long int (*)(long int*) noexcept'} and 'int')
   81 |                                 if(time[i][j][i][j] >= 0) count = min(count, time[i][j][i][j]);
      |                                    ~~~~~~~~~~~~~~~~~^~~~
a.cc:81