Language: C++

#include<iostream>
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;

int bfs();
int INF=1000000000;
int h,w,n;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int sx,sy;
int good[1111][1111];
int ans=0;
char life="0";
char map[1111][1111];

int main(){
  cin >> h >> w >> n;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> map[i][j];
      if(map[i][j] == 'S'){
	sy = i;
	sx = j;
      }
    }
  }
  for(int i=1;i<n+1;i++){
    life++;
    ans += bfs();
    cout << ans << endl;
  }
}


int bfs(){
  pueue<P> pue;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      good[i][j] = INF;
    }
  }
  pue.push(P(sy,sx));
  d[sy][sx] = 0;
 
  while(que.size()){
    P p=pue.front(); que.pop();
    if(map[p.first][p.second] < life){
      sy = p.first;
      sx = p.second;
      break;
    }
    for(int i=0;i<4;i++){
      int nx = p.first + dy[i];
      int ny = p.second + dx[i];
      if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
	good[ny][nx] = good[p.first][p.second] + 1;
      }
    }
  }
  return good[sy][sx];
}

Compiler output:
a.cc:17:11: error: invalid conversion from 'const char*' to 'char' [-fpermissive]
   17 | char life="0";
      |           ^~~
      |           |
      |           const char*
a.cc: In function 'int main()':
a.cc:24:14: error: reference to 'map' is ambiguous
   24 |       cin >> map[i][j];
      |              ^~~
In file included from /usr/include/c++/14/map:63,
                 from a.cc:4:
/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:18:6: note:                 'char map [1111][1111]'
   18 | char map[1111][1111];
      |      ^~~
a.cc:25:10: error: reference to 'map' is ambiguous
   25 |       if(map[i][j] == 'S'){
      |          ^~~
/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:18:6: note:                 'char map [1111][1111]'
   18 | char map[1111][1111];
      |      ^~~
a.cc: In function 'int bfs()':
a.cc:40:3: error: 'pueue' was not declared in this scope
   40 |   pueue<P> pue;
      |   ^~~~~
a.cc:40:10: error: expected primary-expression before '>' token
   40 |   pueue<P> pue;
      |          ^
a.cc:40:12: error: 'pue' was not declared in this scope
   40 |   pueue<P> pue;
      |            ^~~
a.cc:47:3: error: 'd' was not declared in this scope
   47 |   d[sy][sx] = 0;
      |   ^
a.cc:49:9: error: 'que' was not declared in this scope
   49 |   while(que.size()){
      |         ^~~
a.cc:51:8: error: reference to 'map' is ambiguous
   51 |     if(map[p.first][p.second] < life){
      |        ^~~
/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:18:6: note:                 'char map [1111][1111]'
   18 | char map[1111][1111];
      |      ^~~
a.cc:59:26: error: 'N' was not declared in this scope
   59 |       if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
      |                          ^
a.cc:59:47: error: 'M' was not declared in this scope
   59 |       if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
      |                                               ^
a.cc:59:52: error: reference to 'map' is ambiguous
   59 |       if(0 <= nx && nx < N && 0 <= ny && ny < M && map[ny][nx] != 'X' && good[ny][nx] == INF){
      |                                                    ^~~
/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:18:6: note:                 'char map [1111][1111]'
   18 | char map[1111][1111];
      |      ^~~