Language: C++

#include<bits/stdc++.h>
using namespace std;
struct ma
{
	int x;
	int y;
};
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 };
char m[1200][1200];
int map[1200][1200];
int main()
{
	int ans = 0;
	int tate, yoko;
	int n;
	cin >> tate >> yoko >> n;
	
	ma sta;
	for (int i = 0; i < tate; i++)
	{
		for (int k = 0; k < yoko; k++)
		{
			cin >> m[i][k];
			if (m[i][k] == 'S')
			{
				sta.x = k;
				sta.y = i;
			}
		}
	}
	int HP = 1;
	queue<ma> hoge;
	for (int i = 0; i < n; i++)
	{
		hoge.push(sta);
		
		memset(map, -1, sizeof(map));
		map[sta.y][sta.x] = 0;
		while (!hoge.empty())
		{
			ma now;
			now = hoge.front();
			hoge.pop();
			for (int k = 0; k < 4; k++)
			{
				if (now.y + dy[k] >= tate || now.x + dx[k] >= yoko)continue;
				if (now.y + dy[k] < 0 || now.x + dx[k] < 0)continue;
				if (m[now.y + dy[k]][now.x + dx[k]] != 'X')
				{
					if (map[now.y + dy[k]][now.x + dx[k]] != -1)
					{
						continue;
					}
					map[now.y + dy[k]][now.x + dx[k]] = map[now.y][now.x] + 1;
					if (m[now.y + dy[k]][now.x + dx[k]] - '0' == HP)
					{
						m[now.y + dy[k]][now.x + dx[k]] = '.';
						ans += map[now.y + dy[k]][now.x + dx[k]];
						while (!hoge.empty())hoge.pop();
						HP++;
						sta.x = now.x + dx[k];
						sta.y = now.y + dy[k];
						break;
					}
					else
					{
						ma hage;
						hage.x = now.x + dx[k];
						hage.y = now.y + dy[k];
						hoge.push(hage);
					}
				}
			}

		/*	for (int i = 0; i < tate; i++)
			{
				for (int k = 0; k < yoko; k++)
				{
					cout << map[i][k] << " ";
				}
				cout << endl;
			}
			cout << endl;*/
		}
	}
	cout << ans << endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:24: error: reference to 'map' is ambiguous
   37 |                 memset(map, -1, sizeof(map));
      |                        ^~~
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~
a.cc:37:40: error: reference to 'map' is ambiguous
   37 |                 memset(map, -1, sizeof(map));
      |                                        ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~
a.cc:38:17: error: reference to 'map' is ambiguous
   38 |                 map[sta.y][sta.x] = 0;
      |                 ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~
a.cc:50:45: error: reference to 'map' is ambiguous
   50 |                                         if (map[now.y + dy[k]][now.x + dx[k]] != -1)
      |                                             ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~
a.cc:54:41: error: reference to 'map' is ambiguous
   54 |                                         map[now.y + dy[k]][now.x + dx[k]] = map[now.y][now.x] + 1;
      |                                         ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~
a.cc:54:77: error: reference to 'map' is ambiguous
   54 |                                         map[now.y + dy[k]][now.x + dx[k]] = map[now.y][now.x] + 1;
      |                                                                             ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~
a.cc:58:56: error: reference to 'map' is ambiguous
   58 |                                                 ans += map[now.y + dy[k]][now.x + dx[k]];
      |                                                        ^~~
/usr/include/c++/14/bits/stl_map.h:102:11: note: candidates are: 'template<class _Key, class _Tp, class _Compare, class _Alloc> class std::map'
  102 |     class map
      |           ^~~
a.cc:10:5: note:                 'int map [1200][1200]'
   10 | int map[1200][1200];
      |     ^~~