Language: C++

#include<iostream>
#include<queue>
#define fi first
#define se second
using namespace std;
int dy[4]={0,0,-1,1},dx[4]={1,-1,0,0};
int X,Y,N;
char field[1000][1001];
pair<int,int> time[1000][1001];
struct point{
    int y,x,t,n;
    point(int y_,int x_,int t_,int n_){
        y=y_;x=x_;t=t_;n=n_;
    }
};
int bfs(int y,int x);
int main(){
    cin>>Y>>X>>N;
    int rep;
    for(int i=0;i<Y;i++)cin>>field[i];
    for(int i=0;i<Y;i++){
        for(int j=0;j<X;j++){
            time[i][j].fi=time[i][j].se=-1;
        }
    }
    for(int i=0;i<Y;i++){
        bool flag=false;
        for(int j=0;j<X;j++){
            if(field[i][j]=='S'){
                rep=bfs(i,j);
                flag=true;
                break;
            }
        }
        if(flag)break;
    }
    cout<<rep<<endl;
    return 0;

}

int bfs(int y,int x){
    point start=point(y,x,0,0);
    queue<point>Q;
    Q.push(start);
    while(Q.size()){

        point a=Q.front();
        Q.pop();
        if(a.y<0 || a.y>=Y ||a.x<0||a.x>=X)continue;

        if(field[a.y][a.x]=='X')continue;

        if(a.n+1==field[a.y][a.x]-'0')a.n++;

        if(a.n>time[a.y][a.x].se){
            time[a.y][a.x].fi=a.t;
            time[a.y][a.x].se=a.n;
        }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
            time[a.y][a.x].fi=a.t;
        }else continue;

        if(a.n==N){
            return a.t;
        }


        for(int i=0;i<4;i++){
            point next=point(a.y+dy[i],a.x+dx[i],a.t+1,a.n);
            Q.push(next);
        }
    }
}

Compiler output:
a.cc:9:30: error: 'std::pair<int, int> time [1000][1001]' redeclared as different kind of entity
    9 | pair<int,int> time[1000][1001];
      |                              ^
In file included from /usr/include/pthread.h:23,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr-default.h:35,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/gthr.h:157,
                 from /usr/include/c++/14/ext/atomicity.h:35,
                 from /usr/include/c++/14/bits/ios_base.h:39,
                 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/time.h:76:15: note: previous declaration 'time_t time(time_t*)'
   76 | extern time_t time (time_t *__timer) __THROW;
      |               ^~~~
a.cc: In function 'int main()':
a.cc:23:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |             time[i][j].fi=time[i][j].se=-1;
      |                   ^
a.cc:23:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |             time[i][j].fi=time[i][j].se=-1;
      |                      ^
a.cc:3:12: error: request for member 'first' in '*(time + (((sizetype)i) + ((sizetype)j)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    3 | #define fi first
      |            ^~~~~
a.cc:23:24: note: in expansion of macro 'fi'
   23 |             time[i][j].fi=time[i][j].se=-1;
      |                        ^~
a.cc:23:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |             time[i][j].fi=time[i][j].se=-1;
      |                                 ^
a.cc:23:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   23 |             time[i][j].fi=time[i][j].se=-1;
      |                                    ^
a.cc:4:12: error: request for member 'second' in '*(time + (((sizetype)i) + ((sizetype)j)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    4 | #define se second
      |            ^~~~~~
a.cc:23:38: note: in expansion of macro 'se'
   23 |             time[i][j].fi=time[i][j].se=-1;
      |                                      ^~
a.cc: In function 'int bfs(int, int)':
a.cc:56:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   56 |         if(a.n>time[a.y][a.x].se){
      |                        ^
a.cc:56:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   56 |         if(a.n>time[a.y][a.x].se){
      |                             ^
a.cc:4:12: error: request for member 'second' in '*(time + (((sizetype)a.point::y) + ((sizetype)a.point::x)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    4 | #define se second
      |            ^~~~~~
a.cc:56:31: note: in expansion of macro 'se'
   56 |         if(a.n>time[a.y][a.x].se){
      |                               ^~
a.cc:57:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |             time[a.y][a.x].fi=a.t;
      |                     ^
a.cc:57:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |             time[a.y][a.x].fi=a.t;
      |                          ^
a.cc:3:12: error: request for member 'first' in '*(time + (((sizetype)a.point::y) + ((sizetype)a.point::x)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    3 | #define fi first
      |            ^~~~~
a.cc:57:28: note: in expansion of macro 'fi'
   57 |             time[a.y][a.x].fi=a.t;
      |                            ^~
a.cc:58:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |             time[a.y][a.x].se=a.n;
      |                     ^
a.cc:58:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |             time[a.y][a.x].se=a.n;
      |                          ^
a.cc:4:12: error: request for member 'second' in '*(time + (((sizetype)a.point::y) + ((sizetype)a.point::x)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    4 | #define se second
      |            ^~~~~~
a.cc:58:28: note: in expansion of macro 'se'
   58 |             time[a.y][a.x].se=a.n;
      |                            ^~
a.cc:59:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                               ^
a.cc:59:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                    ^
a.cc:4:12: error: request for member 'second' in '*(time + (((sizetype)a.point::y) + ((sizetype)a.point::x)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    4 | #define se second
      |            ^~~~~~
a.cc:59:38: note: in expansion of macro 'se'
   59 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                      ^~
a.cc:59:54: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                      ^
a.cc:59:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                           ^
a.cc:3:12: error: request for member 'first' in '*(time + (((sizetype)a.point::y) + ((sizetype)a.point::x)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    3 | #define fi first
      |            ^~~~~
a.cc:59:61: note: in expansion of macro 'fi'
   59 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                             ^~
a.cc:60:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |             time[a.y][a.x].fi=a.t;
      |                     ^
a.cc:60:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |             time[a.y][a.x].fi=a.t;
      |                          ^
a.cc:3:12: error: request for member 'first' in '*(time + (((sizetype)a.point::y) + ((sizetype)a.point::x)))', which is of non-class type 'time_t(time_t*) noexcept' {aka 'long int(long int*) noexcept'}
    3 | #define fi first
      |            ^~~~~
a.cc:60:28: note: in expansion of macro 'fi'
   60 |             time[a.y][a.x].fi=a.t;
      |                            ^~
a.cc:73:1: warning: control reaches end of non-void function [-Wreturn-type]
   73 | }
      | ^