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;
typedef pair<int,int> P;
char field[1000][1001];
P time[1000][1001];
struct point{
    int y,x,t,n;
};
int bfs(int,int);
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={y,x,0,0};
    queue<point>Q;
    Q.push(start);
    while(Q.size()){

        point a;
        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={a.y+dy[i],a.x+dx[i],a.t+1,a.n};
            Q.push(next);
        }


    }



}

Compiler output:
a.cc:10:18: error: 'P time [1000][1001]' redeclared as different kind of entity
   10 | P 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:21:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |             time[i][j].fi=time[i][j].se=-1;
      |                   ^
a.cc:21:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |             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:21:24: note: in expansion of macro 'fi'
   21 |             time[i][j].fi=time[i][j].se=-1;
      |                        ^~
a.cc:21:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |             time[i][j].fi=time[i][j].se=-1;
      |                                 ^
a.cc:21:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   21 |             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:21:38: note: in expansion of macro 'se'
   21 |             time[i][j].fi=time[i][j].se=-1;
      |                                      ^~
a.cc: In function 'int bfs(int, int)':
a.cc:55:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   55 |         if(a.n>time[a.y][a.x].se){
      |                        ^
a.cc:55:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   55 |         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:55:31: note: in expansion of macro 'se'
   55 |         if(a.n>time[a.y][a.x].se){
      |                               ^~
a.cc:56:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   56 |             time[a.y][a.x].fi=a.t;
      |                     ^
a.cc:56:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   56 |             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:56:28: note: in expansion of macro 'fi'
   56 |             time[a.y][a.x].fi=a.t;
      |                            ^~
a.cc:57:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |             time[a.y][a.x].se=a.n;
      |                     ^
a.cc:57:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |             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:57:28: note: in expansion of macro 'se'
   57 |             time[a.y][a.x].se=a.n;
      |                            ^~
a.cc:58:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                               ^
a.cc:58:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |         }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:58:38: note: in expansion of macro 'se'
   58 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                      ^~
a.cc:58:54: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                      ^
a.cc:58:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |         }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:58:61: note: in expansion of macro 'fi'
   58 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                             ^~
a.cc:59:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |             time[a.y][a.x].fi=a.t;
      |                     ^
a.cc:59:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |             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:59:28: note: in expansion of macro 'fi'
   59 |             time[a.y][a.x].fi=a.t;
      |                            ^~
a.cc:77:1: warning: control reaches end of non-void function [-Wreturn-type]
   77 | }
      | ^