Language: C

#include <iostream>
#include <queue>
using namespace std;

const int INF = 1000000;
int H,W;
class Point{
public:
  int tx;
  int ty;
  int kx;
  int ky;
  int f;
  void set(int a,int b,int c,int d,int f){
    tx = a;
    ty = b;
    kx = c;
    ky = d;
    this->f = f;
  }
};

int is_out_of_area(int y,int x){
  return x < 1 || x > W || y < 1 || H > H;
}
int main(){
  char F[52][52];
  int D[52][52];

  int tx,ty,kx,ky;
  int counter = 0;
  while(1){
    cin >> W >> H;
    if(W == 0 && H == 0)
    break;
    cin >> tx >> ty >> kx >> ky;

    for(int y=0;y<=H+1;y++){
      for(int x=0;x<=W+1;x++){
        F[y][x] = 1;
      }
    }
    for(int y=1;y<=H;y++){
      for(int x=1;x<=W;x++){
        D[y][x] = INF;
        int a;
        cin >> a;
        F[y][x] = a;
      }
    }

    queue<Point> qa;
    Point p;
    p.set(tx,ty,kx,ky,0);
    qa.push(p);
    D[p.ty][p.tx] = 0;
    while(1){
      if(qa.empty()){
        cout << "NA" << endl;
        break;
      }
      p = qa.front();
      qa.pop();
      if(p.f >= 100){
        cout << "NA" << endl;
        break;
      }

      if(p.tx == p.kx && p.ty == p.ky){
        cout << p.f << endl;
        break;
      }

      if(D[p.ty-1][p.tx] == INF && D[p.ky+1][p.kx] == INF){

          if(!((is_out_of_area(p.ty-1,p.tx) || F[p.ty-1][p.tx]) && (is_out_of_area(p.ky+1,p.kx) || F[p.ky+1][p.kx]))){
            if(F[p.ty-1][p.tx] || is_out_of_area(p.ty-1,p.tx)){
              Point q;
              q.set(p.tx,p.ty,p.kx,p.ky+1,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else if(is_out_of_area(p.ky+1,p.kx) || F[p.ky+1][p.kx]){
              Point q;
              q.set(p.tx,p.ty-1,p.kx,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else {
              Point q;
              q.set(p.tx,p.ty-1,p.kx,p.ky+1,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            }
          }

      }
      if(D[p.ty+1][p.tx] == INF && D[p.ky-1][p.kx] == INF){
          if(!((is_out_of_area(p.ty+1,p.tx) || F[p.ty+1][p.tx]) && (is_out_of_area(p.ky-1,p.kx) || F[p.ky-1][p.kx]))){
            if(F[p.ty+1][p.tx] || is_out_of_area(p.ty+1,p.tx)){
              Point q;
              q.set(p.tx,p.ty,p.kx,p.ky-1,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else if(is_out_of_area(p.ky-1,p.kx) || F[p.ky-1][p.kx]){
              Point q;
              q.set(p.tx,p.ty+1,p.kx,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else {
              Point q;
              q.set(p.tx,p.ty+1,p.kx,p.ky-1,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            }
          }

      }

      if(D[p.ty][p.tx-1] == INF && D[p.ky][p.kx+1] == INF){
          if(!((is_out_of_area(p.ty,p.tx-1) || F[p.ty][p.tx-1]) && (is_out_of_area(p.ky,p.kx+1) || F[p.ky][p.kx+1]))){
            if(F[p.ty][p.tx-1] || is_out_of_area(p.ty,p.tx-1)){
              Point q;
              q.set(p.tx,p.ty,p.kx+1,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else if(is_out_of_area(p.ky,p.kx+1) || F[p.ky][p.kx+1]){
              Point q;
              q.set(p.tx-1,p.ty,p.kx,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else {
              Point q;
              q.set(p.tx-1,p.ty,p.kx+1,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            }
          }

      }
      if(D[p.ty][p.tx+1] == INF && D[p.ky][p.kx-1] == INF){
          if(!((is_out_of_area(p.ty,p.tx+1) || F[p.ty][p.tx+1]) && (is_out_of_area(p.ky,p.kx-1) || F[p.ky][p.kx-1]))){
            if(F[p.ty][p.tx+1] || is_out_of_area(p.ty,p.tx+1)){
              Point q;
              q.set(p.tx,p.ty,p.kx-1,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else if(is_out_of_area(p.ky,p.kx-1) || F[p.ky][p.kx-1]){
              Point q;
              q.set(p.tx+1,p.ty,p.kx,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            } else {
              Point q;
              q.set(p.tx+1,p.ty,p.kx-1,p.ky,p.f+1);
              qa.push(q);
              D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
            }
          }
      }
      counter++;
    /*  if(D[p.ty-1][p.tx] == INF && D[p.ky+1][p.kx] == INF){
        if(is_out_of_area(p.ty-1,p.tx) == 0 || is_out_of_area(p.ky+1,p.kx) == 0){
          if(F[p.ty-1][p.tx] == 0 || F[p.ky+1][p.kx] == 0){
            Point q;
            q.set(p.tx,p.ty-1,p.kx,p.ky+1);
            qa.push(q);
            D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
          }
        }
      }
      if(D[p.ty+1][p.tx] == INF && D[p.ky-1][p.kx] == INF){
        if(is_out_of_area(p.ty-1,p.tx) == 0 || is_out_of_area(p.ky+1,p.kx) == 0){
          if(F[p.ty+1][p.tx] == 0 || F[p.ky-1][p.kx] == 0){
            Point q;
            q.set(p.tx,p.ty+1,p.kx,p.ky-1);
            qa.push(q);
            D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
          }
        }
      }
      if(D[p.ty][p.tx-1] == INF && D[p.ky][p.kx+1] == INF){
        if(is_out_of_area(p.ty,p.tx) == 0 || is_out_of_area(p.ky,p.kx) == 0){
          if(F[p.ty][p.tx-1] == 0 || F[p.ky][p.kx+1] == 0){
            Point q;
            q.set(p.tx-1,p.ty,p.kx+1,p.ky);
            qa.push(q);
            D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
          }
        }
      }
      if(D[p.ty][p.tx+1] == INF && D[p.ky][p.kx-1] == INF){
        if(is_out_of_area(p.ty,p.tx+1) == 0 || is_out_of_area(p.ky,p.kx-1) == 0){
          if(F[p.ty][p.tx+1] == 0 || F[p.ky][p.kx-1] == 0){
            Point q;
            q.set(p.tx+1,p.ty,p.kx-1,p.ky);
            qa.push(q);
            D[q.ty][q.tx] = D[p.ty][p.tx] + 1;
          }
        }
      }
      */
    }

  }
  return 0;
}



Compiler output:
main.c:1:10: fatal error: iostream: No such file or directory
    1 | #include <iostream>
      |          ^~~~~~~~~~
compilation terminated.