Language: C++

#include <iostream>

using namespace std;

typedef struct {
	int x, y;
} Vector;

char map[16 + 2][16 + 2];
unsigned int data[16][16][16][16][10];
int ans;
int ans_x, ans_y;

int change(char move[], Vector mv[])
{
	int i = 0;
	while (move[i] != '\0'){
		mv[i].x = mv[i].y = 0;
		switch (move[i]){
		  case '5':
		  	break;
		  case '8':
		  	mv[i].y = -1;
			break;
		  case '6':
		  	mv[i].x = 1;
			break;
		  case '4':
		  	mv[i].x = -1;
			break;
		  case '2':
		  	mv[i].y = 1;
			break;
		}
		i++;
	}
	return (i);
}

int calc(int sx, int sy, int gx, int gy, Vector mv[], int move_count, int depth)
{
	int mx, my;
	
	
	if (map[sx][sy] == -1 || map[sx][sy] == '#' || ans <= depth){
		return (0);
	}
	if (sx == gx && sy == gy){
		if (ans > depth){
			ans = depth;
			ans_x = sx - 1;
			ans_y = sy - 1;
		}
		return (0);
	}
	if (data[sx - 1][sy - 1][gx - 1][gy - 1][depth % move_count] == 1){
		return (0);
	}
	data[sx - 1][sy - 1][gx - 1][gy - 1][depth % move_count] = 1;
	
	mx = mv[depth % move_count].x;
	my = mv[depth % move_count].y;
	
	if (map[gx + mx][gy + my] != -1){
		gx += mx;
		gy += my;
	}
	calc(sx + 1, sy, gx, gy, mv, move_count, depth + 1);
	calc(sx - 1, sy, gx, gy, mv, move_count, depth + 1);
	calc(sx, sy + 1, gx, gy, mv, move_count, depth + 1);
	calc(sx, sy - 1, gx, gy, mv, move_count, depth + 1);
	calc(sx, sy,     gx, gy, mv, move_count, depth + 1);
	
	data[sx - 1][sy - 1][gx - 1][gy - 1][depth % move_count] = 0;
	
	return (0);
}

int main(void)
{
	int hight, width;
	int sx, sy, gx, gy;
	char move[11];
	Vector mv[10];
	int move_count;
	
	while (1){
		ans = 16 * 16 * 16 * 16 * 10;
		cin >> hight >> width;
		if (hight == 0 && width == 0)break;
		for (int y = 0; y < hight + 2; y++){
			char str[16 + 1];
			if (y == 0 || y == hight + 1){
				for (int x = 0; x < width + 2; x++){
					map[x][y] = -1;
				}
			}
			else {
				cin >> str;
				map[0][y] = map[width + 1][y] = -1;
				for (int x = 0; x < width; x++){
					if (str[x] == 'A'){
						sx = x + 1;
						sy = y;
					}
					if (str[x] == 'B'){
						gx = x + 1;
						gy = y;
					}
					map[x + 1][y] = str[x];
				}
			}
		}
		cin >> move;
		memset(data, 0, 16 * 16 * 16 * 16 * 10);
		
		move_count = change(move, mv);
		
		calc(sx, sy, gx, gy, mv, move_count, 0);
		
		if (ans == 16 * 16 * 16 * 16 * 10){
			cout << "impossible" << endl;
		}
		else {
			cout << ans << ' ' << ans_y << ' ' << ans_x << endl;
		}
	}
	
	return (0);
}

Compiler output:
a.cc: In function 'int calc(int, int, int, int, Vector*, int, int)':
a.cc:56:13: error: reference to 'data' is ambiguous
   56 |         if (data[sx - 1][sy - 1][gx - 1][gy - 1][depth % move_count] == 1){
      |             ^~~~
In file included from /usr/include/c++/14/string:53,
                 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/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:14: note:                 'unsigned int data [16][16][16][16][10]'
   10 | unsigned int data[16][16][16][16][10];
      |              ^~~~
a.cc:59:9: error: reference to 'data' is ambiguous
   59 |         data[sx - 1][sy - 1][gx - 1][gy - 1][depth % move_count] = 1;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:14: note:                 'unsigned int data [16][16][16][16][10]'
   10 | unsigned int data[16][16][16][16][10];
      |              ^~~~
a.cc:74:9: error: reference to 'data' is ambiguous
   74 |         data[sx - 1][sy - 1][gx - 1][gy - 1][depth % move_count] = 0;
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:14: note:                 'unsigned int data [16][16][16][16][10]'
   10 | unsigned int data[16][16][16][16][10];
      |              ^~~~
a.cc: In function 'int main()':
a.cc:115:24: error: reference to 'data' is ambiguous
  115 |                 memset(data, 0, 16 * 16 * 16 * 16 * 10);
      |                        ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:14: note:                 'unsigned int data [16][16][16][16][10]'
   10 | unsigned int data[16][16][16][16][10];
      |              ^~~~
a.cc:115:17: error: 'memset' was not declared in this scope
  115 |                 memset(data, 0, 16 * 16 * 16 * 16 * 10);
      |                 ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include <iostream>
  +++ |+#include <cstring>
    2 |