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;
    point(int y_,int x_,int t_,int n_){
        y=y_;x=x_;t=t_;n=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=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: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:24:19: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |             time[i][j].fi=time[i][j].se=-1;
      |                   ^
a.cc:24:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |             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:24:24: note: in expansion of macro 'fi'
   24 |             time[i][j].fi=time[i][j].se=-1;
      |                        ^~
a.cc:24:33: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |             time[i][j].fi=time[i][j].se=-1;
      |                                 ^
a.cc:24:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   24 |             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:24:38: note: in expansion of macro 'se'
   24 |             time[i][j].fi=time[i][j].se=-1;
      |                                      ^~
a.cc: In function 'int bfs(int, int)':
a.cc:57:24: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |         if(a.n>time[a.y][a.x].se){
      |                        ^
a.cc:57:29: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   57 |         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:57:31: note: in expansion of macro 'se'
   57 |         if(a.n>time[a.y][a.x].se){
      |                               ^~
a.cc:58:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |             time[a.y][a.x].fi=a.t;
      |                     ^
a.cc:58:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   58 |             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:58:28: note: in expansion of macro 'fi'
   58 |             time[a.y][a.x].fi=a.t;
      |                            ^~
a.cc:59:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |             time[a.y][a.x].se=a.n;
      |                     ^
a.cc:59:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   59 |             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:59:28: note: in expansion of macro 'se'
   59 |             time[a.y][a.x].se=a.n;
      |                            ^~
a.cc:60:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                               ^
a.cc:60:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |         }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:60:38: note: in expansion of macro 'se'
   60 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                      ^~
a.cc:60:54: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                      ^
a.cc:60:59: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   60 |         }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:60:61: note: in expansion of macro 'fi'
   60 |         }else if(a.n==time[a.y][a.x].se&&a.t<time[a.y][a.x].fi){
      |                                                             ^~
a.cc:61:21: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |             time[a.y][a.x].fi=a.t;
      |                     ^
a.cc:61:26: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   61 |             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:61:28: note: in expansion of macro 'fi'
   61 |             time[a.y][a.x].fi=a.t;
      |                            ^~
a.cc:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^