Language: C++

#include <bits/stdc++.h>
using namespace std;

int table[51][51];

bool memo[51][51][51][51];

int main() {

    while(1){

        int w,h;

        //scanf(" %d %d",&w,&h);

        cin >> w >> h;

        if(w==0&&h==0) break;

        int tx,ty,kx,ky;

        //scanf(" %d %d %d %d",&tx,&ty,&kx,&ky);

        cin >> tx >> ty >> kx >> ky;

        tx--;ty--;kx--;ky--;

        for(int i=0;i<51;i++){
            for(int j=0;j<51;j++){
                table[i][j] = 1;
                for(int k=0;k<51;k++){
                    for(int r=0;r<51;r++){
                        memo[i][j][k][r] = false;
                    }
                }
            }
        }

        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                //scanf(" %d",&table[i][j]);
                cin >> table[i][j];
            }
        }
        
        if(table[v[0]][v[1]] == 1 || table[v[2]][v[3]] == 1){
            cout << "NA" << endl;
            continue;
        }

        /*printf("\n");

        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                printf("%d ",table[i][j]);
            }
            printf("\n");
        }*/

        //memset(memo,false,sizeof(memo));

        queue<vector<int> > q;

        vector<int> v(5);

        v[0] = tx; v[1] = ty; v[2] = kx; v[3] = ky; v[4] = 0;

        q.push(v);

        bool check = false;

        while(!q.empty()){

            v = q.front(); q.pop();

            if(v[4] >= 100){
                break;
            }

            /*if(v[0] >= w || v[1] >= h || v[2] >= w || v[3] >= h || v[0] < 0 || v[1] < 0 || v[2] < 0 || v[3] < 0 || table[v[0]][v[1]] == 1 || table[v[2]][v[3]] == 1){
                continue;
            }*/

            if(memo[v[0]][v[1]][v[2]][v[3]]){
                continue;
            }

            if(v[0] == v[2] && v[1] == v[3]){
                check = true;
                cout << v[4] << endl;
                break;
            }

            memo[v[0]][v[1]][v[2]][v[3]] = true;

            v[4]++;

            vector<int> before(5);

            for(int i=0;i<5;i++){
                before[i] = v[i];
            }

            v[0]--; v[2]++;

            if(v[0] > 0 && v[2] < w && table[v[0]][v[1]] == 0 && table[v[2]][v[3]] == 0) {
                q.push(v);
            }

            for(int i=0;i<5;i++){
                v[i] = before[i];
            }

            v[0]++; v[2]--;

            if(v[2] > 0 && v[0] < w && table[v[0]][v[1]] == 0 && table[v[2]][v[3]] == 0) {
                q.push(v);
            }

            for(int i=0;i<5;i++){
                v[i] = before[i];
            }

            v[1]++; v[3]--;

            if(v[3] > 0 && v[1] < h && table[v[0]][v[1]] == 0 && table[v[2]][v[3]] == 0) {
                q.push(v);
            }

            for(int i=0;i<5;i++){
                v[i] = before[i];
            }

            v[1]--; v[3]++;

            if(v[1] > 0 && v[3] < h && table[v[0]][v[1]] == 0 && table[v[2]][v[3]] == 0) {
                q.push(v);
            }

            /*if(v[0] >= w || v[1] >= h || v[2] >= w || v[3] >= h || v[0] < 0 || v[1] < 0 || v[2] < 0 || v[3] < 0 || table[v[0]][v[1]] == 1 || table[v[2]][v[3]] == 1){

            }else {
                q.push(v);
            }*/



        }

        if(!check){
            cout << "NA" << endl;
        }



    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:46:18: error: 'v' was not declared in this scope
   46 |         if(table[v[0]][v[1]] == 1 || table[v[2]][v[3]] == 1){
      |                  ^