Language: C++

#include<iostream>
#include<queue>
#include<map>
using namespace std;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
class state{
public:
	int tx;
	int ty;
	int kx;
	int ky;
};
int main() {
	int W, H, tx, ty, kx, ky;
	bool d[52][52];
	map<state,bool> m;
	state num;
	state copy;
	while (true) {
		cin >> W >> H;
		if (W == 0)break;
		for (int i = 0; i < H+2; i++) {
			for (int j = 0; j < W+2; j++) {
				d[i][j] = 1;
			}
		}
		cin >> tx >> ty >> kx >> ky;
		for (int i = 1; i < H + 1; i++) {
			for (int j = 1; j < W + 1; j++) {
				cin >> d[j][i];
			}
		}
		num.tx = tx;
		num.ty = ty;
		num.kx = kx;
		num.ky = ky;
		queue<state> q;
		q.push(num);
		int qsize = q.size();
		int loopcount = 0;
		while (!q.empty()) {
			num = q.front();
			q.pop();
			if (qsize == 0) {
				qsize = q.size()+1;
				loopcount++;
				if (loopcount == 100) {
					cout << "NA" << endl;
					break;
				}
			}
			qsize--;
			m[num] = true;
			if (num.tx == num.kx && num.ty == num.ky) {
				cout << loopcount << endl;
				break;
			}
			for (int i = 0; i < 4; i++) {
				if (!d[num.tx + dx[i]][num.ty + dy[i]]) {
					copy.tx = num.tx + dx[i];
					copy.ty = num.ty + dy[i];
				}
				if (!d[num.kx - dx[i]][num.ky - dy[i]]) {
					copy.kx = num.kx - dx[i];
					copy.ky = num.ky - dy[i];
				}
				if (!m[copy]) {
					q.push(copy);
				}
			}
			if (q.empty()) {
				cout << "NA" << endl;
			}
		}
	}
	return 0;
}


Compiler output:
In file included from /usr/include/c++/14/string:49,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 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/c++/14/bits/stl_function.h: In instantiation of 'constexpr bool std::less<_Tp>::operator()(const _Tp&, const _Tp&) const [with _Tp = state]':
/usr/include/c++/14/bits/stl_map.h:511:32:   required from 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = state; _Tp = bool; _Compare = std::less<state>; _Alloc = std::allocator<std::pair<const state, bool> >; mapped_type = bool; key_type = state]'
  511 |         if (__i == end() || key_comp()(__k, (*__i).first))
      |                             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
a.cc:54:9:   required from here
   54 |                         m[num] = true;
      |                              ^
/usr/include/c++/14/bits/stl_function.h:405:20: error: no match for 'operator<' (operand types are 'const state' and 'const state')
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
In file included from /usr/include/c++/14/string:48:
/usr/include/c++/14/bits/stl_iterator.h:448:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_Iterator>&)'
  448 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:448:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const state' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const reverse_iterator<_Iterator>&, const reverse_iterator<_IteratorR>&)'
  493 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:493:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const state' is not derived from 'const std::reverse_iterator<_Iterator>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note: candidate: 'template<class _IteratorL, class _IteratorR> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorR>&)'
 1694 |     operator<(const move_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1694:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const state' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note: candidate: 'template<class _Iterator> constexpr bool std::operator<(const move_iterator<_IteratorL>&, const move_iterator<_IteratorL>&)'
 1760 |     operator<(const move_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/14/bits/stl_iterator.h:1760:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_function.h:405:20: note:   'const state' is not derived from 'const std::move_iterator<_IteratorL>'
  405 |       { return __x < __y; }
      |                ~~~~^~~~~