Language: C++

  State(int a,int b,int c,int d):a(a),b(b),c(c),d(d){};
};

int h,w;
int table[51][51],memo[51][51][51][51];
int Y[4]={-1,0,1,0};
int X[4]={0,1,0,-1};

bool in(int a,int b){
  if(a<0 || b<0 || h<=a || w<=b)return false;
  return true;
}

void init(){
  for(int i=0;i<51;i++)
    for(int j=0;j<51;j++)
      for(int k=0;k<51;k++)
	for(int l=0;l<51;l++)memo[i][j][k][l]=inf;
}

int main()
{
  int a,b,c,d;
  while(1){
    cin>>w>>h;
    if(h+w==0)break;
    cin>>b>>a>>d>>c;
    a--;b--;c--;d--;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++)cin>>table[i][j];
    init();

    queue<State> q;
    q.push(State(a,b,c,d));
    memo[a][b][c][d]=0;

    int ans=inf;
    while(!q.empty()){
      State u=q.front();
      q.pop();

      if(u.a==u.c && u.b==u.d){
	ans=min(memo[u.a][u.b][u.c][u.d],ans);
        continue;
      }

      if(memo[u.a][u.b][u.c][u.d]>=100)continue;

      for(int i=0;i<4;i++){
	int A=u.a+Y[i],B=u.b+X[i],C=u.c+Y[(i+2)%4],D=u.d+X[(i+2)%4];
	if(table[A][B] || !in(A,B)){
	  A=u.a;
	  B=u.b;
	}
	if(table[C][D] || !in(C,D)){
	  C=u.c;
	  D=u.d;
	}
	if(memo[A][B][C][D]>memo[u.a][u.b][u.c][u.d]+1){
	  q.push(State(A,B,C,D));
	  memo[A][B][C][D]=memo[u.a][u.b][u.c][u.d]+1;
	}
      }
    }
    if(ans>=100)cout<<"NA"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Compiler output:
a.cc:1:3: error: ISO C++ forbids declaration of 'State' with no type [-fpermissive]
    1 |   State(int a,int b,int c,int d):a(a),b(b),c(c),d(d){};
      |   ^~~~~
a.cc: In function 'int State(int, int, int, int)':
a.cc:1:34: error: only constructors take member initializers
    1 |   State(int a,int b,int c,int d):a(a),b(b),c(c),d(d){};
      |                                  ^
a.cc:1:54: warning: no return statement in function returning non-void [-Wreturn-type]
    1 |   State(int a,int b,int c,int d):a(a),b(b),c(c),d(d){};
      |                                                      ^
a.cc: At global scope:
a.cc:2:1: error: expected declaration before '}' token
    2 | };
      | ^
a.cc: In function 'void init()':
a.cc:18:47: error: 'inf' was not declared in this scope; did you mean 'int'?
   18 |         for(int l=0;l<51;l++)memo[i][j][k][l]=inf;
      |                                               ^~~
      |                                               int
a.cc: In function 'int main()':
a.cc:25:5: error: 'cin' was not declared in this scope; did you mean 'in'?
   25 |     cin>>w>>h;
      |     ^~~
      |     in
a.cc:32:5: error: 'queue' was not declared in this scope
   32 |     queue<State> q;
      |     ^~~~~
a.cc:32:18: error: 'q' was not declared in this scope
   32 |     queue<State> q;
      |                  ^
a.cc:36:13: error: 'inf' was not declared in this scope; did you mean 'int'?
   36 |     int ans=inf;
      |             ^~~
      |             int
a.cc:38:12: error: expected ';' before 'u'
   38 |       State u=q.front();
      |            ^~
      |            ;
a.cc:41:10: error: 'u' was not declared in this scope
   41 |       if(u.a==u.c && u.b==u.d){
      |          ^
a.cc:42:13: error: 'min' was not declared in this scope; did you mean 'main'?
   42 |         ans=min(memo[u.a][u.b][u.c][u.d],ans);
      |             ^~~
      |             main
a.cc:46:15: error: 'u' was not declared in this scope
   46 |       if(memo[u.a][u.b][u.c][u.d]>=100)continue;
      |               ^
a.cc:49:15: error: 'u' was not declared in this scope
   49 |         int A=u.a+Y[i],B=u.b+X[i],C=u.c+Y[(i+2)%4],D=u.d+X[(i+2)%4];
      |               ^
a.cc:50:21: error: 'B' was not declared in this scope
   50 |         if(table[A][B] || !in(A,B)){
      |                     ^
a.cc:54:18: error: 'C' was not declared in this scope
   54 |         if(table[C][D] || !in(C,D)){
      |                  ^
a.cc:54:21: error: 'D' was not declared in this scope
   54 |         if(table[C][D] || !in(C,D)){
      |                     ^
a.cc:58:20: error: 'B' was not declared in this scope
   58 |         if(memo[A][B][C][D]>memo[u.a][u.b][u.c][u.d]+1){
      |                    ^
a.cc:58:23: error: 'C' was not declared in this scope
   58 |         if(memo[A][B][C][D]>memo[u.a][u.b][u.c][u.d]+1){
      |                       ^
a.cc:58:26: error: 'D' was not declared in this scope
   58 |         if(memo[A][B][C][D]>memo[u.a][u.b][u.c][u.d]+1){
      |                          ^
a.cc:64:17: error: 'cout' was not declared in this scope
   64 |     if(ans>=100)cout<<"NA"<<endl;
      |                 ^~~~
a.cc:64:29: error: 'endl' was not declared in this scope
   64 |     if(ans>=100)cout<<"NA"<<endl;
      |                             ^~~~
a.cc:65:10: error: 'cout' was not declared in this scope
   65 |     else cout<<ans<<endl;
      |          ^~~~
a.cc:65:21: error: 'endl' was not declared in this scope
   65 |     else cout<<ans<<endl;
      |                     ^~~~