criyle/codenet-compile-errors huggingface dataset:
Language: C++

#include<iostream>
#include<cstdio>
#include<queue>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)

using namespace std;


struct P{
    int x;
    int y;
};

int w,h,n;
const int INF = 1e+8;
char feld[1010][1010];
int d[1010][1010];
int sx,sy,gx,gy;
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
int ans=0;
P che[15];


int bfs(){
    for(int i=0;i<n,i++){
        P sp=che[i];
        sx=che[i].x;
        sy=che[i].y;
        gx=che[i+1].x;
        gy=che[i+1].y;
        queue<P> que;
        for(int y=0;y<h;y++)for(int x=0;x<w;x++)d[y][x]=INF;
        que.push(sp);
        d[sy][sx]=0;
        while(!que.empty()){
            P p=que.front();
            que.pop();
            int x=p.x;
            int y=p.y;
            if(x==gx&&y==gy){
                ans+=d[gy][gx];
                break;
            }
            REP(int i=0;i<4;i++){
                int nx=x+dx[i];
                int ny=y+dy[i];
                if(nx<0||ny<0&&nx>=w&&ny>=h)continue;
                if(feld[ny][nx]!='X'&&d[ny][nx]==INF){
                    P next;
                    next.x=nx;
                    next.y=ny;
                    que.push(next);
                    d[ny][nx]=d[y][x]+1;
                }
            }
        }
    }
    return 0;
}

int main(){
    cin>>h>>w>>n;
    REP(int y=0;y<h;y++){
        REP(int x=0;x<w;x++){
            scanf(" %c",&feld[y][x]);
            if(feld[y][x]=='S'){
                che[0].x=x;
                che[0].y=y;
            }else if(feld[y][x]>='1'&&feld[y][x]<='9'){
                char c=feld[y][x];
                che[c-'0'].x=x;
                che[c-'0'].y=y;
            }
        }
    }
    bfs();
    cout<<ans<<endl;
    return 0;
}

Compiler output:
a.cc:46:32: error: macro "REP" requires 2 arguments, but only 1 given
   46 |             REP(int i=0;i<4;i++){
      |                                ^
a.cc:4:9: note: macro "REP" defined here
    4 | #define REP(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc:65:24: error: macro "REP" requires 2 arguments, but only 1 given
   65 |     REP(int y=0;y<h;y++){
      |                        ^
a.cc:4:9: note: macro "REP" defined here
    4 | #define REP(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc:66:28: error: macro "REP" requires 2 arguments, but only 1 given
   66 |         REP(int x=0;x<w;x++){
      |                            ^
a.cc:4:9: note: macro "REP" defined here
    4 | #define REP(i,n) for(int i=0;i<(n);i++)
      |         ^~~
a.cc: In function 'int bfs()':
a.cc:27:24: error: expected ';' before ')' token
   27 |     for(int i=0;i<n,i++){
      |                        ^
      |                        ;
a.cc:46:13: error: 'REP' was not declared in this scope
   46 |             REP(int i=0;i<4;i++){
      |             ^~~
a.cc: In function 'int main()':
a.cc:65:5: error: 'REP' was not declared in this scope
   65 |     REP(int y=0;y<h;y++){
      |     ^~~
Language: C++

#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
int m,n;
int maxe=0;
int che=0;
int k;
struct node{
  int x,y;
};
char mape[1111][1111];
int d[1111][1111];
queue<node> q;
int da[]={0,0,1,-1};
int db[]={1,-1,0,0};
void bfs(){
  while(!q.empty()&&che<k){
    node nn;
    int x=q.front().x;
    int y=q.front().y;
    q.pop();
    if(mape[x][y]>='0'&&mape[x][y]<='9'){
      che++;
      maxe+=d[x][y];
    }
    else mape[x][y]='X';
    for(int i=0;i<4;i++)
      if(x+da[i]>=0&&x+da[i]<m&&y+db[i]>=0&&y+db[i]<n&&mape[x+da[i]][y+db[i]]!='X'){
	int w=x+da[i];
	int e=y+db[i];
	d[w][e]=d[x][y]+1;
	nn.x=w;
	nn.y=e;
	mape[w][e]='X'
	q.push(nn);
      }
  }
}
int main(){
  cin>>m>>n>>k;
  while(!q.empty())q.pop();
  node nn;
  memset(d,-1,sizeof(d));
  for(int i=0;i<m;i++)
    for(int j=0;j<n;j++){
      cin>>mape[i][j];
      if(mape[i][j]=='S'){
	nn.x=i;
	nn.y=j;
	d[i][j]=0;
	q.push(nn);
	mape[i][j]='X';
      }
    }
  bfs();
  cout<<maxe<<"\n";
}

Compiler output:
a.cc: In function 'void bfs()':
a.cc:35:23: error: expected ';' before 'q'
   35 |         mape[w][e]='X'
      |                       ^
      |                       ;
   36 |         q.push(nn);
      |         ~
Language: C++

#include<iostream>
#include<queue>
#include<stdlib.h>
#include<pair.h>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
    d[sx][sy]=0;
    cheese.push(p(sx,sy));
    while(cheese.size()){
        p test=cheese.front();
        cheese.pop();
        if(plat[test.first][test.second]==energy){
            sx=test.first;sy=test.second;
            return d[test.first][test.second];
        }
        for(int i=0;i<4;++i){
            int nx=test.first+dx[i];int ny=test.second+dy[i];
            if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
                cheese.push(p(nx,ny));
                d[nx][ny]=d[test.first][test.second]+1;
            }
        }

    }
}

int main()
{

    cin>>W>>H>>N;
    int sx,sy;
    for(int i=0;i<W;++i){
        for(int j=0;j<H;++j){
            char u;
            cin>>u;
            if(u=='S'){
                sx=i;sy=j;
            }
            plat[i][j]=u;
        }
    }
    char e='1';
    int ans=0;
    while(N--){
        memset(d,-1,sizeof(d));
        ans+=bfs(sx,sy,e++);
        while(cheese.size())cheese.pop();

    }
    cout<<ans<<endl;

}

Compiler output:
a.cc:4:9: fatal error: pair.h: No such file or directory
    4 | #include<pair.h>
      |         ^~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<queue>
#include<stdlib.h>
#include<utility>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
    d[sx][sy]=0;
    cheese.push(p(sx,sy));
    while(cheese.size()){
        p test=cheese.front();
        cheese.pop();
        if(plat[test.first][test.second]==energy){
            sx=test.first;sy=test.second;
            return d[test.first][test.second];
        }
        for(int i=0;i<4;++i){
            int nx=test.first+dx[i];int ny=test.second+dy[i];
            if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
                cheese.push(p(nx,ny));
                d[nx][ny]=d[test.first][test.second]+1;
            }
        }

    }
}

int main()
{

    cin>>W>>H>>N;
    int sx,sy;
    for(int i=0;i<W;++i){
        for(int j=0;j<H;++j){
            char u;
            cin>>u;
            if(u=='S'){
                sx=i;sy=j;
            }
            plat[i][j]=u;
        }
    }
    char e='1';
    int ans=0;
    while(N--){
        memset(d,-1,sizeof(d));
        ans+=bfs(sx,sy,e++);
        while(cheese.size())cheese.pop();

    }
    cout<<ans<<endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:53:9: error: 'memset' was not declared in this scope
   53 |         memset(d,-1,sizeof(d));
      |         ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    4 | #include<utility>
  +++ |+#include <cstring>
    5 | using namespace std;
a.cc: In function 'int bfs(int&, int&, char)':
a.cc:33:1: warning: control reaches end of non-void function [-Wreturn-type]
   33 | }
      | ^
Language: C++

#include<iostream>
#include<queue>
#include<stdlib.h>
#include<utility>
#include<memory>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
    d[sx][sy]=0;
    cheese.push(p(sx,sy));
    while(cheese.size()){
        p test=cheese.front();
        cheese.pop();
        if(plat[test.first][test.second]==energy){
            sx=test.first;sy=test.second;
            return d[test.first][test.second];
        }
        for(int i=0;i<4;++i){
            int nx=test.first+dx[i];int ny=test.second+dy[i];
            if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
                cheese.push(p(nx,ny));
                d[nx][ny]=d[test.first][test.second]+1;
            }
        }

    }
}

int main()
{

    cin>>W>>H>>N;
    int sx,sy;
    for(int i=0;i<W;++i){
        for(int j=0;j<H;++j){
            char u;
            cin>>u;
            if(u=='S'){
                sx=i;sy=j;
            }
            plat[i][j]=u;
        }
    }
    char e='1';
    int ans=0;
    while(N--){
        memset(d,-1,sizeof(d));
        ans+=bfs(sx,sy,e++);
        while(cheese.size())cheese.pop();

    }
    cout<<ans<<endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:54:9: error: 'memset' was not declared in this scope
   54 |         memset(d,-1,sizeof(d));
      |         ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include<memory>
  +++ |+#include <cstring>
    6 | using namespace std;
a.cc: In function 'int bfs(int&, int&, char)':
a.cc:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^
Language: C++

#include<iostream>
#include<queue>
#include<stdlib.h>
#include<utility>
#include<memory>
#include<string>
using namespace std;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
const int INF=-1;
char plat[1005][1005];
int d[1005][1005];
typedef pair<int,int> p;
int H,W,N;
queue<p> cheese;
int bfs(int& sx,int& sy,char energy)
{
    d[sx][sy]=0;
    cheese.push(p(sx,sy));
    while(cheese.size()){
        p test=cheese.front();
        cheese.pop();
        if(plat[test.first][test.second]==energy){
            sx=test.first;sy=test.second;
            return d[test.first][test.second];
        }
        for(int i=0;i<4;++i){
            int nx=test.first+dx[i];int ny=test.second+dy[i];
            if(nx>=0&&nx<W&&ny>=0&&ny<H&&plat[nx][ny]!='X'&&d[nx][ny]==INF){
                cheese.push(p(nx,ny));
                d[nx][ny]=d[test.first][test.second]+1;
            }
        }

    }
}

int main()
{

    cin>>W>>H>>N;
    int sx,sy;
    for(int i=0;i<W;++i){
        for(int j=0;j<H;++j){
            char u;
            cin>>u;
            if(u=='S'){
                sx=i;sy=j;
            }
            plat[i][j]=u;
        }
    }
    char e='1';
    int ans=0;
    while(N--){
        memset(d,-1,sizeof(d));
        ans+=bfs(sx,sy,e++);
        while(cheese.size())cheese.pop();

    }
    cout<<ans<<endl;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:9: error: 'memset' was not declared in this scope
   55 |         memset(d,-1,sizeof(d));
      |         ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    5 | #include<memory>
  +++ |+#include <cstring>
    6 | #include<string>
a.cc: In function 'int bfs(int&, int&, char)':
a.cc:35:1: warning: control reaches end of non-void function [-Wreturn-type]
   35 | }
      | ^
Language: C++

#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

int h, w, n;

char map[1001][1001];

int vis[1001][1001];

const int v[2][4] = { {1,0,-1,0},{0,-1,0,1} };

queue<pair<int ,int>> Pos;
queue <pair<int, pair< int, int > >> que;//?????°?????§?¨?


int main() {
	cin >> h >> w >> n;
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> map[i][j];
			if (map[i][j] == 'S')que.push(make_pair(0,make_pair(i,j)));
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= h; j++) {
			for (int k = 1; k <= w; k++) {
				if (map[j][k] - '0' == i)Pos.push(make_pair(j,k));
			}
		}
	}
	int ct = 0;
	while (Pos.size()) {
		pair<int, int > P = Pos.front();
		hPos.pop();
		while (que.size()) {
			pair<int,pair< int,int > > a = que.front();
			que.pop();
			if (vis[a.second.first][a.second.second] != 0)continue;
			vis[a.second.first][a.second.second] = a.first + 1;
			if (a.second.first == P.first&&a.second.second == P.second) {
				ct += vis[a.second.first][a.second.second];
				for (int i = 1; i <= h; i++) {
					for (int j = 1; j <= w; j++) {
						vis[i][j] = 0;
					}
				}
				while (que.size())que.pop();
				if(Pos.size())que.push(make_pair(0,make_pair(a.second.first,a.second.second)));
				ct -= 1;
				break;
			}
			for (int i = 0; i < 4; i++) {
				int px= a.second.first + v[0][i], py= a.second.second + v[1][i];
				if (1 <= px&&px <= h && 1 <= py&&py <= w&&vis[px][py] == 0 && map[px][py] != 'S'&&map[px][py]!='X') {
					que.push(make_pair(vis[a.second.first][a.second.second], make_pair(px, py)));
				}
			}
		}
	}
	cout << ct << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:37:17: error: 'hPos' was not declared in this scope; did you mean 'Pos'?
   37 |                 hPos.pop();
      |                 ^~~~
      |                 Pos
Language: C++

#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<algorithm>
#define INF 1000000
using namespace std;
typedef pair<int,int> P;
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
bool map[1000][1000];
int x[10],y[10];
int ans=0;
int h,w,n;

int search(int n){
    int d[1000][1000];
    std::fill(d,d+sizeof(d),INF);
    int sx=x[n],sy=y[n];
    int tx=x[n+1],ty=y[n+1];
    queue<P> q;
    q.push(P(sx,sy));
    d[sx][sy]=0;
    while(1){
        P p=q.front();
        q.pop();
        sx=p.first,sy=p.second;
        if(sx==tx&&sy==ty) return d[tx][ty];
        for(int i=0;i<4;i++){
            int X=sx+dx[i];
            int Y=sy+dy[i];
            if(map[X][Y]&&X>=0&&X<h&&Y>=0&&Y<w){
                q.push(P(X,Y));
                d[X][Y]=d[sx][sy]+1;
            }
        }
    }
}
int main(){
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c=getchar();
            if(c!='x'){
                map[i][j]=true;
                if(c=='S'){
                    x[0]=i,y[0]=j;
                }else{
                    int k=atoi(&c);
                    x[k]=i;
                    y[k]=j;
                }
            }
        }
        getchar();
    }
    for(int i=0;i<n;i++){
        ans+=search(i);
    }
    printf("%d\n",ans);
}

Compiler output:
In file included from /usr/include/c++/14/deque:62,
                 from /usr/include/c++/14/queue:62,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[1000]; _Tp = int; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int (*)[1000]; _Tp = int]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[1000]; _Tp = int]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:17:14:   required from here
   17 |     std::fill(d,d+sizeof(d),INF);
      |     ~~~~~~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const int' to 'int [1000]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~
Language: C++

#include <cstdio>
#include <queue>
#define min(x,y) ((x)<(y)?(x):(y))
#define INFI 65535

using namespace std;
typedef pair<int, int> P;

int Strength = 1;
int Maps[1010][1010];
int dist[1010][1010];
int H, W, N;
int hor[] = {1,0,-1,0};
int ver[] = {0,-1,0,1};
int ans;


void clear();
void show();
P bfs(int cheese,P n);

int main(void) {
    scanf("%d %d %d\n", &H, &W, &N);
    P s,e;
    for (int i = 0; i<H; i++) {
        for (int j = 0; j<W; j++) {
            Maps[i][j] = getchar();
            if (Maps[i][j]=='S') {s.first = i; s.second = j;}
            if (Maps[i][j]=='0'+N) {e.first = i; e.second = j;}
        }
        getchar();
    }

    
    P tmp;
    tmp.first = s.first; tmp.second = s.second;
    
    for (int i = 1; i<=N; i++) {
        clear();
        tmp = bfs(i, tmp);
    }
    
    
    
    printf("%d\n", ans);
    return 0;
}

P bfs(int cheese,P n) {
    P end;
    queue<P> que;
    que.push(n);
    dist[n.first][n.second] = 0;
    
    while (que.size()) {
        P top = que.front();
        
        que.pop();
        for (int i = 0; i<4; i++) {
            int nx = top.first+ver[i], ny = top.second+hor[i];
            if (nx>=0 && nx<H && ny>=0 && ny<W && dist[nx][ny]==INFI) {
                if (Maps[nx][ny]=='.' || (isdigit(Maps[nx][ny]) && cheese!=Maps[nx][ny]-'0'))  {
                    que.push(P(nx,ny));
                    dist[nx][ny] = min(dist[nx][ny], dist[top.first][top.second]+1);
                } else if (isdigit(Maps[nx][ny]) && cheese==Maps[nx][ny]-'0') {
                    que.push(P(nx,ny));
                    dist[nx][ny] = min(dist[nx][ny], dist[top.first][top.second]+1);
                    end.first = nx; end.second = ny;
                    break;
                }
            }
        }
    }
    ans += dist[end.first][end.second];
    return end;
}

void clear() {
    for (int i = 0; i<H; i++)
        for (int j = 0; j<W; j++)
            dist[i][j] = INFI;
}

Compiler output:
a.cc: In function 'P bfs(int, P)':
a.cc:62:43: error: 'isdigit' was not declared in this scope
   62 |                 if (Maps[nx][ny]=='.' || (isdigit(Maps[nx][ny]) && cheese!=Maps[nx][ny]-'0'))  {
      |                                           ^~~~~~~
Language: C++

#include <iostream>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>

#define INF 0x7f7f7f7f
#define PI acos(-1.0)

#define L(x)    (x) << 1
#define R(x)    (x) << 1 | 1
#define lowbit(x)   (x)&(-x)
#define Mid(l, r)   (l + r) >> 1
#define Min(x, y)   (x) < (y) ? (x) : (y)
#define Max(x, y)   (x) < (y) ? (y) : (x)
#define iabs(x)     (x) < 0 ? -(x) : (x)
#define CLR(arr, val)    memset(arr, val, sizeof(arr))

using namespace std;

char map[1024][1024];
bool vis[1024][1024];
int cur, h, w;
int dir[4][2] = {1, 0, -1, 0, 0, 1, 0, -1};

struct node {
	int x, y, step;
} sta;

bool check(int x, int y) {
	if (x >= 0 && x < h && y >= 0 && y < w && !vis[x][y] && map[x][y] != 'X')	return true;
	return false;
}



void bfs(node s) {
	memset(vis, 0, sizeof(vis));
	
	queue<node> que;
	que.push(s);
	node next;
	while (!que.empty()) {
		s = que.front(); que.pop();
		
		next.step = now.step + 1;
		for (int i = 0; i < 4; i++) {
			next.x = now.x + dir[i][0];
			next.y = now.y + dir[i][1];

			if (check(next.x, next.y)) {
				vis[s.x][s.y] = true;
				if (map[next.x][next.y] == cur + '0') {
					sta = next;
					return ;
				}
				que.push(next);
			}
		}
	}
}

int main() {
	int n;
	while (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')	sta.x = i, sta.y = j, map[i][j] = '.';
			}
		}
		sta.step = 0;
		for (cur = 1; cur <= n; cur++) {
			bfs(sta);
		}
		cout << sta.step << endl;
	}
	return 0;
}

Compiler output:
a.cc: In function 'void bfs(node)':
a.cc:47:29: error: 'now' was not declared in this scope; did you mean 'pow'?
   47 |                 next.step = now.step + 1;
      |                             ^~~
      |                             pow
Language: C++

#include <stdio.h>

#include <queue>

using namespace std;

char map[1000][1000];
bool visited[1000][1000];
int W, H, N;
int startR, startC;
int targetR[10];
int targetC[10];

int dr[4] = {-1, 1, 0, 0};
int dc[4] = {0, 0, -1, 1};

int getMinTime() {
  int time = 0;
  int curR = startR;
  int curC = startC;
  for (int i = 0; i < N; ++i) {
    memset(visited, false, sizeof(visited));
    queue<int> q;
    q.push((curR << 16) | curC);
    visited[curR][curC] = true;
    while (!visited[targetR[i]][targetC[i]]) {
      time++;
      int count = q.size();
      while (count-- > 0) {
        int node = q.front();
        q.pop();
        int r = node >> 16;
        int c = node & 0xffff;
        for (int j = 0; j < 4; ++j) {
          int nr = r + dr[j];
          int nc = c + dc[j];
          if (nr >= 0 && nr < H && nc >= 0 && nc < W && !visited[nr][nc] && map[nr][nc] != 'X') {
            visited[nr][nc] = true;
            q.push((nr << 16) | nc);
          }
        }
      }
    }
    curR = targetR[i];
    curC = targetC[i];
  }
  return time;
}

int main() {
  //freopen("Cheese.in", "r", stdin);
  while (scanf("%d%d%d", &H, &W, &N) == 3 && W != 0 && H != 0 && N != 0) {
    for (int r = 0; r < H; ++r) {
      for (int c = 0; c < W; ++c) {
        char ch;
        do {
          ch = getchar();
        } while (isspace(ch));
        if (ch == 'S') {
          startR = r;
          startC = c;
        } else if (isdigit(ch)) {
          int index = ch - '0' - 1;
          targetR[index] = r;
          targetC[index] = c;
        }
        map[r][c] = ch;
      }
    }
    int result = getMinTime();
    printf("%d\n", result);
  }
  return 0;
}

Compiler output:
a.cc: In function 'int getMinTime()':
a.cc:22:5: error: 'memset' was not declared in this scope
   22 |     memset(visited, false, sizeof(visited));
      |     ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <queue>
  +++ |+#include <cstring>
    4 | 
a.cc: In function 'int main()':
a.cc:58:18: error: 'isspace' was not declared in this scope
   58 |         } while (isspace(ch));
      |                  ^~~~~~~
a.cc:62:20: error: 'isdigit' was not declared in this scope
   62 |         } else if (isdigit(ch)) {
      |                    ^~~~~~~
Language: C++

#include <iostream>
#include <vector>
std::vector<std::pair<int, int>> next_list(const int &x, const int &y) {
	return { std::make_pair(x + 1, y), std::make_pair(x - 1, y), std::make_pair(x, y + 1), std::make_pair(x, y - 1) };
}
template<typename T>
class Queue {
public:
	Queue(const int &n) :vector(n), f(0), b(0) {};
	T front() const {
		return vector.at(f);
	}
	T back() const {
		return vector.at(b);
	}
	void pop() {
		f = (f + 1) % vector.size();
	}
	void push(T f) {
		vector.at(b) = f;
		b = (b + 1) % vector.size();
	}
	void clear() {
		f = 0;
		b = 0;
	}
private:
	std::vector<T> vector;
	int f, b;
};
struct Route {
	Route(const int &ax = 0, const int &ay = 0, const int &an = 0, const int &atime = 0) :x(ax), y(ay), n(an), time(atime) {};
	int x, y, n, time;
	bool operator<(const Route &other) const {
		return time < other.time;
	}
};
int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
	queue.clear();
	queue.push(start);
	while (vector.at(queue.front().y).at(queue.front().x) != start.n + 1) {
		for (const auto &coord : next_list(queue.front().x, queue.front().y)) {
			if (vector.at(coord.second).at(coord.first) >= 0 && memo.at(coord.second).at(coord.first) != start.n) {
				memo.at(coord.second).at(coord.first) = start.n;
				queue.push(Route(coord.first, coord.second, 0, queue.front().time + 1));
			}
		}
		queue.pop();
	}
	if (start.n + 1 == goal) {
		return queue.front().time;
	}
	else {
		return wfs(vector, memo, queue, Route(queue.front().x, queue.front().y, start.n + 1, queue.front().time), goal);
	}
}
int main() {
	int h, w, n;
	std::cin >> h >> w >> n;
	std::vector<std::vector<int>> vector(h + 2, std::vector<int>(w + 2, -1));
	Route start(0, 0, 0, 0);
	char *arg = new char[w + 2];
	for (auto i = 1; i <= h; ++i) {
		std::cin >> arg;
		for (auto j = 1; j <= w; ++j) {
			switch (arg[j - 1]) {
			case '.':
				vector.at(i).at(j) = 0;
				break;
			case 'X':
				vector.at(i).at(j) = -1;
				break;
			case 'S':
				vector.at(i).at(j) = 0;
				start = Route(j, i, 0, 0);
				break;
			default:
				vector.at(i).at(j) = arg[j - 1] - '0';
			}
		}
	}
	delete[] arg;
	arg = nullptr;
	std::vector<std::vector<int>> memo(h + 2, std::vector<int>(w + 2, -1));
	std::cout << wfs(vector, memo, Queue<Route>(h * w * 4), start, n);
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:85:40: error: cannot bind non-const lvalue reference of type 'Queue<Route>&' to an rvalue of type 'Queue<Route>'
   85 |         std::cout << wfs(vector, memo, Queue<Route>(h * w * 4), start, n);
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~
a.cc:38:105: note:   initializing argument 3 of 'int wfs(const std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, Queue<Route>&, const Route&, const int&)'
   38 | int wfs(const std::vector<std::vector<int>> &vector, std::vector<std::vector<int>> &memo, Queue<Route> &queue, const Route &start, const int &goal) {
      |                                                                                           ~~~~~~~~~~~~~~^~~~~
Language: C++

#include<cstdio>
#include<algorithm>
#include<queue>
#include <iostream>
#define inf 1000000
using namespace std;
int H,W,N,x0,y0;
char map[1005][1005];int d[1005][1005];
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};int d[1005][1005];
typedef pair<int,int>P;
struct position
{
	int rx,ry,e;
}xy[9];
bool comp(const position a,const position b)
{
	return a.e<b.e;
}
int bfs(int sx,int sy,int gx,int gy)
{
	int tx,ty;
	queue<P>q;

	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)
		d[i][j]=inf;
	}
	q.push(P(sx,sy));
	d[sx][sy]=0;
	while(!q.empty())
	{
		P p=q.front();
		if(p.first==gx&&p.second==gy)
		return d[p.first][p.second];
		q.pop();
		for(int i=0;i<4;i++)
		{
			tx=p.first+dx[i];
			ty=p.second+dy[i];
			if(tx>=0&&tx<H&&ty>=0&&ty<W&&map[tx][ty]!='X'&&d[tx][ty]==inf)
			{
				d[tx][ty]=d[p.first][p.second]+1;
				q.push(P(tx,ty));
			}
		}
	}
}
int main(void)
{
	while(scanf("%d%d%d",&H,&W,&N)==3)
	{
		int x1[9],y1[9];
		for(int i=0;i<H;i++)
		scanf("%s",&map[i]);
		int t=0;
		for(int i=0;i<H;i++)
		{
			for(int j=0;j<W;j++)
			{
				if(map[i][j]=='S')
				{
					x0=i;
					y0=j;
				}
				if(map[i][j]-'0'>0&&map[i][j]-'0'<=9)
				{
					xy[t].rx=i;
					xy[t].ry=j;
					xy[t].e=map[i][j]-'0';
					t++;
				}
			}
		}

		sort(xy,xy+N,comp);
		int ans=bfs(x0,y0,xy[0].rx,xy[0].ry);
		for(int i=0;i<N-1;i++)
		ans+=bfs(xy[i].rx,xy[i].ry,xy[i+1].rx,xy[i+1].ry);
		printf("%d\n",ans);
	}
	return 0;
}

Compiler output:
a.cc:7:14: warning: built-in function 'y0' declared as non-function [-Wbuiltin-declaration-mismatch]
    7 | int H,W,N,x0,y0;
      |              ^~
a.cc:10:26: error: redefinition of 'int d [1005][1005]'
   10 | int dy[4]={0,-1,0,1};int d[1005][1005];
      |                          ^
a.cc:8:26: note: 'int d [1005][1005]' previously declared here
    8 | char map[1005][1005];int d[1005][1005];
      |                          ^
a.cc: In function 'int bfs(int, int, int, int)':
a.cc:49:1: warning: control reaches end of non-void function [-Wreturn-type]
   49 | }
      | ^
Language: C++

#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

struct node {
	int i;
	int j;
	char val;
};

int H, W, N;//H(1 <= H <= 1000)、W(1 <= W <=1000)、N(1 <= N <= 9)
char m[1001][1001];
queue<node> q;

bool flag = 0;
int t1 = 0;
char flag_m[1001][1001];
void search(int i, int j, char val)
{
	if (flag_m[i][j]<val) {
		if (m[i][j] == 'X')
		{
			return;
		}
		if (m[i][j] == '.' || m[i][j] != val)
		{
			q.push({ i,j,val });
			//flag_m[i][j] = true;
			t1++;
		}
		if (m[i][j] == val)
		{
			if (val == ('0' + N))
			{
				flag = 1;
			}
			else
			{
				q.push({ i,j,val + 1 });
				//flag_m[i][j] = true;
				m[i][j] = '.';
				t1++;
			}
		}
	}
	return;
}
int main()
{
	int si, sj;
	scanf("%d %d %d",&H,&W,&N);
	for (int i = 1;i <= H; i++)
	{
		getchar();
		for (int j = 1; j <= W; j++)
		{
			scanf("%c",&(m[i][j]));
			if (m[i][j] == 'S')
			{
				si = i;
				sj = j;
			}
		}
	}

	//
	
	q.push({si,sj,'1'});
	memset(flag_m,'0',sizeof(flag_m));
	int t = 1;
	int time=0;
	
	while (!q.empty() &&(!flag))
	{
		time++;
		t1 = 0;
		while (t-- &&(!flag))
		{
			node n1 = q.front(); q.pop();
			si = n1.i; sj = n1.j;
			flag_m[si][sj] = n1.val;
			if (si > 1)
			{
				search(si-1,sj,n1.val);
			}
			if (si < H)
			{
				search(si + 1, sj, n1.val);
			}
			if (sj > 1)
			{
				search(si, sj-1, n1.val);
			}
			if (sj < W)
			{
				search(si, sj+1, n1.val);
			}

		}
		t = t1;
	}
	printf("%d\n",time);
	return 1;
}

Compiler output:
a.cc: In function 'void search(int, int, char)':
a.cc:40:50: warning: narrowing conversion of '(((int)val) + 1)' from 'int' to 'char' [-Wnarrowing]
   40 |                                 q.push({ i,j,val + 1 });
      |                                              ~~~~^~~
a.cc: In function 'int main()':
a.cc:70:9: error: 'memset' was not declared in this scope
   70 |         memset(flag_m,'0',sizeof(flag_m));
      |         ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    3 | #include <queue>
  +++ |+#include <cstring>
    4 | using namespace std;
Language: C++

// 111.cpp : 定?控制台?用程序的入口点。
//

#include "stdafx.h"
#include<stdio.h>
#include <queue>
using namespace std;

#define N 1001
int cols,rows,n;
char a[N][N];
bool visited[N][N] = {0};
int minTime;
int direction[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};

struct Point{
	int x;
	int y;
};

bool isInMap(Point p){
	if(p.x < 0 || p.x >= rows)return 0;
	if(p.y < 0 || p.y >= cols)return 0;
	else return 1;
}

int bfs(Point startP,Point endP){
	//printf("strat x = %d y= %d\n",startP.x,startP.y);
	//printf("end x = %d y = %d\n",endP.x,endP.y);
	
	int count = 1;
	queue<Point> point;
	int time =0;
	point.push(startP);
	visited[startP.x][startP.y] = 1;

	while(point.size()){
		int count1 = count;
		//printf("count1 = %d\n",count1);
		count = 0;
		time++;
		for(int i = 0; i < count1; i++)
		{
			//printf("time = %d",time);
			Point cur = point.front();
			
			point.pop();
			for(int j = 0 ; j < 4; j++)
			{
				Point temp;
				temp.x = cur.x + direction[j][0];
				temp.y = cur.y + direction[j][1];
				if(isInMap(temp) && a[temp.x][temp.y] != 'X' && visited[temp.x][temp.y] == 0)
				{
					point.push(temp);
					visited[temp.x][temp.y] = 1;
					count++;
				}
				if(temp.x == endP.x && temp.y == endP.y)return time;
			}
		}
	}


}

int main(){
	Point startP,endP;
	int totalStep = 0;
    scanf("%d%d%d",&rows,&cols,&n);
	getchar();

	for(int i = 0; i < rows; i++)
	{
		for(int j = 0 ; j < cols; j++)
		{
			scanf("%c",&a[i][j]);
			if(a[i][j] == 'S'){a[i][j] = '0';}
		}
		getchar();
	}

	minTime = 100000;
	for(int k = 0; k < n; k++)
	{
		for(int i = 0; i < rows; i++)
			for(int j = 0; j <cols; j++)
			{
				if((int)a[i][j] == (k+48)){startP.x = i;startP.y = j;}
				if((int)a[i][j] == (k+1+48)){endP.x = i;endP.y = j;}
				visited[i][j] = 0;
			}
		totalStep += bfs(startP,endP);
	}
	printf("%d",totalStep);
}

Compiler output:
a.cc:4:10: fatal error: stdafx.h: No such file or directory
    4 | #include "stdafx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;
int H, W,N;
int time = 0;
int flag = 0;  //   ?志是否?束
int flagt = 0;   //   ??一个?点有几个相??点
char SearchMap[1001][1001];
int SearchFlag[1001][1001] = {0};
struct node
{
	int IndexX;
	int IndexY;
	int value;
};

queue<node> q;                                                            

void FoundTheNext(int x,int y,int val)
{                                     
	if (SearchFlag[x][y] < val)
	{
		if (SearchMap[x][y] == 'X')
			return;
		if (SearchMap[x][y] - '0' == val)
		{
			if (val == N)
				flag = 1;
			else
			{
				q.push({ x,y,val + 1 });
				SearchMap[x][y] = '.';
				flagt++;
			}
			
		}
		if (SearchMap[x][y] == '.'|| SearchMap[x][y]-'0'!=val)
		{
			q.push({ x,y,val});
			flagt++;
		}
		return;
	}
	
}

int main()
{
	scanf("%d %d %d",&H,&W,&N);
	int starti = 0, startj = 0;  //  ???始的位置

	for (int i = 1; i <= H; i++)
	{
		getchar();
		for (int j = 1; j <= W; j++)
		{
			scanf("%c", &(SearchMap[i][j]));
			if (SearchMap[i][j] == 'S')
			{
				starti = i;
				startj = j;
			}
		}
	}

	q.push({starti,startj,1});  //  ?始体力?1
	int resultTime = 0;   //  ??走的?数、??

	int t1 = 1;

	while (!q.empty()&&flag==0)
	{
		
		resultTime++;
		flagt = 0;

		while (t1--&&flag == 0)
		{
			node nodeflag = q.front();

			int x = nodeflag.IndexX, y = nodeflag.IndexY, value = nodeflag.value;

			q.pop();

			SearchFlag[x][y] = value;   //   ?置??数据的?

			if (x > 1)
				FoundTheNext(x - 1, y, value);
			if (x < H)
				FoundTheNext(x + 1, y, value);
			if (y > 1)
				FoundTheNext(x, y - 1, value);
			if (y < W)
				FoundTheNext(x, y + 1, value);
		}
		t1 = flagt;
	}
	if (flag == 1)
		printf("%d",resultTime);

	return 1;

}

Compiler output:
a.cc:7:5: error: 'int time' redeclared as different kind of entity
    7 | int time = 0;
      |     ^~~~
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;
      |               ^~~~
Language: C++

#include<iostream>
#include<cstdio>
#include<queue>

using namespace std;
int H, W,N;
int flag = 0;  //   ?志是否?束
int flagt = 0;   //   ??一个?点有几个相??点
char SearchMap[1001][1001];
int SearchFlag[1001][1001] = {0};
struct node
{
	int IndexX;
	int IndexY;
	int value;
};

queue<node> q;                                                            

void FoundTheNext(int x,int y,int val)
{                                     
	if (SearchFlag[x][y] < val)
	{
		if (SearchMap[x][y] == 'X')
			return;
		if (SearchMap[x][y] - '0' == val)
		{
			if (val == N)
				flag = 1;
			else
			{
				q.push({ x,y,val + 1 });
				SearchMap[x][y] = '.';
				flagt++;
			}
			
		}
		if (SearchMap[x][y] == '.'|| SearchMap[x][y]-'0'!=val)
		{
			q.push({ x,y,val});
			flagt++;
		}
		return;
	}
	
}

int main()
{
	scanf_s("%d %d %d",&H,&W,&N);
	int starti = 0, startj = 0;  //  ???始的位置

	for (int i = 1; i <= H; i++)
	{
		getchar();
		for (int j = 1; j <= W; j++)
		{
			scanf_s("%c", &(SearchMap[i][j]));
			if (SearchMap[i][j] == 'S')
			{
				starti = i;
				startj = j;
			}
		}
	}

	q.push({starti,startj,1});  //  ?始体力?1
	int resultTime = 0;   //  ??走的?数、??

	int t1 = 1;

	while (!q.empty()&&flag==0)
	{
		
		resultTime++;
		flagt = 0;

		while (t1--&&flag == 0)
		{
			node nodeflag = q.front();

			int x = nodeflag.IndexX, y = nodeflag.IndexY, value = nodeflag.value;

			q.pop();

			SearchFlag[x][y] = value;   //   ?置??数据的?

			if (x > 1)
				FoundTheNext(x - 1, y, value);
			if (x < H)
				FoundTheNext(x + 1, y, value);
			if (y > 1)
				FoundTheNext(x, y - 1, value);
			if (y < W)
				FoundTheNext(x, y + 1, value);
		}
		t1 = flagt;
	}
	if (flag == 1)
		printf_s("%d\n",resultTime);
	system("pause");
	return 1;

}

Compiler output:
a.cc: In function 'int main()':
a.cc:50:9: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
   50 |         scanf_s("%d %d %d",&H,&W,&N);
      |         ^~~~~~~
      |         scanf
a.cc:100:17: error: 'printf_s' was not declared in this scope; did you mean 'printf'?
  100 |                 printf_s("%d\n",resultTime);
      |                 ^~~~~~~~
      |                 printf
Language: C++

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <queue>
using namespace std;

char ma[1005][1005];int vis[1005][1005];
int w,h,n;

int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

struct node
{
    int x,y,time;
};
node start;

void bfs(char ed)
{
    queue<node> que;
    que.push(start);
    vis[start.x][start.y]=1;
    while(!que.empty())
    {
        node no=que.front();
        que.pop();
        for(int i=0;i<4;i++)
        {
            int x=no.x+dx[i];
            int y=no.y+dy[i];
            if(vis[x][y]||x>=h||x<0||y>=w||y<0||ma[x][y]=='X')
                continue;
            if(ma[x][y]==ed)
            {
                start.x=x;
                start.y=y;
                start.time=no.time+1;
                return ;
            }
            vis[x][y]=1;
            node no1;
            no1.x=x;no1.y=y;no1.time=no.time+1;
            que.push(no1);
        }
    }
}

int main()
{
    while(~scanf("%d %d %d\n", & h, & w, & n))
    {
        for(int i=0;i<h;i++)
        {
            //scanf("%s",&ma[i]);
            gets(ma[i]);
for(int j=0;j<w;j++)
                if(ma[i][j]=='S')
                {
                    start.x=i;
                    start.y=j;
                    start.time=0;
                }

        }
            for(int i=0;i<n;i++)
            {
                memset(vis,0,sizeof(vis));
                bfs(i+'1');
            }

            printf("%d\n",start.time);
    }
    return 0; 
}

Compiler output:
a.cc: In function 'int main()':
a.cc:56:13: error: 'gets' was not declared in this scope; did you mean 'getw'?
   56 |             gets(ma[i]);
      |             ^~~~
      |             getw
Language: C++

#include<iostream>
#include<deque>

using namespace std;

int H, W, N;
char mapT[1000][1000];
int vis[1000][1000];
int temp_x = 0, temp_y;
char temp;
int final_min_route = 0;
int dir[4][2] = { {-1,0},{0,1},{1,0},{0,-1} };

struct location {
	int x, y, route;
};

location findSmallRouteBFS(int x, int y, char factory) {
	memset(vis, 0, sizeof(vis));
	deque<location> que;
	location temp = { x,y,0 };
	que.push_back(temp);
	vis[x][y] = 1;
	while (!que.empty()) {
		location st = que.front();
		que.pop_front();
		if (mapT[st.x][st.y] == factory) {
			return st;
		}
		for (int i = 0; i < 4; ++i) {
			int t_x = st.x + dir[i][0];
			int t_y = st.y + dir[i][1];
			if (t_x < 0 || t_x >= H || t_y < 0 || t_y >= W || mapT[t_x][t_y] == 'X') {
				continue;
			}
			location temp = { t_x,t_y,st.route + 1 };
			if (!vis[t_x][t_y]) {
				vis[t_x][t_y] = 1;
				que.push_back(temp);
			}
		}
	}

}

int main() {
	cin >> H >> W >> N;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; ++j) {
			cin >> temp;
			mapT[i][j] = temp;
			if (temp == 'S') {
				mapT[i][j] = '0';
				temp_x = i;
				temp_y = j;
			}
		}
	}

	for (int factory = 1; factory != N + 1; ++factory) {

		location lo = findSmallRouteBFS(temp_x, temp_y, mapT[temp_x][temp_y] + 1);
		temp_x = lo.x;
		temp_y = lo.y;
		final_min_route += lo.route;
	}

	cout << final_min_route << endl;
	//system("pause");
	return 0;
}

Compiler output:
a.cc: In function 'location findSmallRouteBFS(int, int, char)':
a.cc:19:9: error: 'memset' was not declared in this scope
   19 |         memset(vis, 0, sizeof(vis));
      |         ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<deque>
  +++ |+#include <cstring>
    3 | 
a.cc:44:1: warning: control reaches end of non-void function [-Wreturn-type]
   44 | }
      | ^
Language: C++

#include <iostream>   
#include <queue>

const int MAX_H = 1000;
const int MAX_W = 1000;
const int a = 100000000;

using namespace std;

typedef pair<int, int> P;


int H = 0, W = 0, N = 0; 
 
int food[11][2];
char cheese[MAX_H][MAX_W] = {0}; 
int r[MAX_H][MAX_W]; 
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; 

int search(int &sx, int &sy, int &ex, int &ey)
{
 
    P p;
    queue<P> que;
    for(int i=0; i<H; i++)
   {
        for(int j=0; j<W; j++)
       {
           r[i][j] = a;

        }
    }
    que.push(P(sx,sy));
    r[sx][sy] = 0;

    while(que.size())
   {  
        p = que.front();
        que.pop();
        if(p.first == ex && p.second == ey)
			break;
	

	    for(int i=0; i<4; i++)
	   {
		    int xn = p.first + dx[i];
		    int yn = p.second + dy[i];


		    if(xn >= 0 && xn < H && yn >= 0 && yn < W && cheese[xn][yn]!='X' && r[xn][yn] == a )
		   {
			    que.push(P(xn,yn));
			    r[xn][yn] = r[p.first][p.second] + 1;
		    }
	    }

	}
	return r[ex][ey];
}

int main()
{
	int dis = 0;
    cin >> H >> W >> N;
    for(int i=0; i<H; i++)
   {
        for(int j=0; j<W; j++)
       {
          cin >> cheese[i][j];
          if(cheese[i][j] == 'S')
         {
             food[0][0] = i;
             food[0][1] = j;
             cheese[i][j] = '.';
          }
          if(cheese[i][j]>48&&cheese[i][j]<58)
         {
             int num = cheese[i][j] - 48;  
             factor[num][0] = i;
             factor[num][1] = j;
          }
       }
    }
   

    for(int i=0; i<N; i++)
   {
       dis += search(food[i][0], food[i][1], food[i+1][0], food[i+1][1]); 
    }
    
	cout << dis << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:79:14: error: 'factor' was not declared in this scope
   79 |              factor[num][0] = i;
      |              ^~~~~~
Language: C++

#include<stack> 
#include<queue> 
#include "StdAfx.h"
const int MAX_H = 1000;
const int MAX_W = 1000;
const int a = 100000000;

using namespace std;

typedef pair<int, int> P;


int H = 0, W = 0, N = 0; 
 
int food[11][2];
char cheese[MAX_H][MAX_W] = {0}; 
int r[MAX_H][MAX_W]; 
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; 

int search(int &sx, int &sy, int &ex, int &ey)
{
 
    P p;
    queue<P> que;
    for(int i=0; i<H; i++)
   {
        for(int j=0; j<W; j++)
       {
           r[i][j] = a;

        }
    }
    que.push(P(sx,sy));
    r[sx][sy] = 0;

    while(que.size())
   {  
        p = que.front();
        que.pop();
        if(p.first == ex && p.second == ey)
			break;
	

	    for(int i=0; i<4; i++)
	   {
		    int xn = p.first + dx[i];
		    int yn = p.second + dy[i];


		    if(xn >= 0 && xn < H && yn >= 0 && yn < W && cheese[xn][yn]!='X' && r[xn][yn] == a )
		   {
			    que.push(P(xn,yn));
			    r[xn][yn] = r[p.first][p.second] + 1;
		    }
	    }

	}
	return r[ex][ey];
}

int main()
{
	int dis = 0;
    cin >> H >> W >> N;
    for(int i=0; i<H; i++)
   {
        for(int j=0; j<W; j++)
       {
          cin >> cheese[i][j];
          if(cheese[i][j] == 'S')
         {
             food[0][0] = i;
             food[0][1] = j;
             cheese[i][j] = '.';
          }
          if(cheese[i][j]>48&&cheese[i][j]<58)
         {
             int num = cheese[i][j] - 48;  
             factor[num][0] = i;
             factor[num][1] = j;
          }
       }
    }
   

    for(int i=0; i<N; i++)
   {
       dis += search(food[i][0], food[i][1], food[i+1][0], food[i+1][1]); 
    }
    
	cout << dis << endl;
    return 0;
}

Compiler output:
a.cc:3:10: fatal error: StdAfx.h: No such file or directory
    3 | #include "StdAfx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include "StdAfx.h"
#include <iostream>   
#include<stack> 
#include<queue> 
#include<string> 
#include <math.h>
using namespace std;

const int MAX_H = 1000;
const int MAX_W = 1000;
const int a = 100000000;

typedef pair<int, int> P;

int H = 0, W = 0, N = 0; 
 
int food[11][2];
char cheese[MAX_H][MAX_W] = {0}; 
int r[MAX_H][MAX_W]; 
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; 

int search(int &sx, int &sy, int &ex, int &ey)
{
 
    P p;
    queue<P> que;
    for(int i=0; i<H; i++)
   {
        for(int j=0; j<W; j++)
       {
           r[i][j] = a;

        }
    }
    que.push(P(sx,sy));
    r[sx][sy] = 0;

    while(que.size())
   {  
        p = que.front();
        que.pop();
        if(p.first == ex && p.second == ey)
			break;
	

	    for(int i=0; i<4; i++)
	   {
		    int xn = p.first + dx[i];
		    int yn = p.second + dy[i];


		    if(xn >= 0 && xn < H && yn >= 0 && yn < W && cheese[xn][yn]!='X' && r[xn][yn] == a )
		   {
			    que.push(P(xn,yn));
			    r[xn][yn] = r[p.first][p.second] + 1;
		    }
	    }

	}
	return r[ex][ey];
}

int main()
{
	int dis = 0;
    cin >> H >> W >> N;
    for(int i=0; i<H; i++)
   {
        for(int j=0; j<W; j++)
       {
          cin >> cheese[i][j];
          if(cheese[i][j] == 'S')
         {
             food[0][0] = i;
             food[0][1] = j;
             cheese[i][j] = '.';
          }
          if(cheese[i][j]>48&&cheese[i][j]<58)
         {
             int num = cheese[i][j] - 48;  
             food[num][0] = i;
             food[num][1] = j;
          }
       }
    }
   

    for(int i=0; i<N; i++)
   {
       dis += search(food[i][0], food[i][1], food[i+1][0], food[i+1][1]); 
    }
    
	cout << dis << endl;
    return 0;
}

Compiler output:
a.cc:1:10: fatal error: StdAfx.h: No such file or directory
    1 | #include "StdAfx.h"
      |          ^~~~~~~~~~
compilation terminated.
Language: C++

#include<iostream>
#include<vector>
using namespace std;

char ma[1001][1001];
bool visited[1001][1001];
int h,w,n;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int sx,sy;
vector<pair<int,int> >vec(10);

int bfs(int x,int y,int d){
    if(ma[y][x]-'0'==d){
        return 0;
    }
    visited[y][x]=1;
    int ret=100000000;
    for(int i=0;i<4;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>=0&&nx<w&&ny>=0&&ny<h&&ma[ny][nx]!='X'&&!visited[ny][nx]){
            ret=min(ret,bfs(nx,ny,d));
        }
    }
    visited[y][x]=0;
    return ret+1;
}

int main(){
    memset(visited,0,sizeof(visited));
    cin>>h>>w>>n;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>ma[i][j];
            if(ma[i][j]>'0'&&ma[i][j]<='9'){
                vec[ma[i][j]-'0']=make_pair(i, j);
            }
            if(ma[i][j]=='S'){
                vec[0]=make_pair(i, j);
            }
        }
    }
    int c=0;
    for(int i=1;i<=n;i++){
        c+=bfs(vec[i-1].second,vec[i-1].first,i);
    }
    cout<<c<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:31:5: error: 'memset' was not declared in this scope
   31 |     memset(visited,0,sizeof(visited));
      |     ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    2 | #include<vector>
  +++ |+#include <cstring>
    3 | using namespace std;
Language: C++

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<queue>
using namespace std;

struct OZAWA
{
	int x;
	int y;
	int c;
};
int Flag[1000][1000];
char MAP[1000][1000];
queue<OZAWA> Q;
int main(void)
{
	int H,W,N,Nc=0,X[10],Y[10];
	OZAWA ba,v;
	int mv[4][2]={{0,-1},{1,0},{0,1},{-1,0}};
	char Cheese[10] ={'1','2','3','4','5','6','7','8','9'};
	memset(MAP,'X',sizeof(MAP));
	memset(Flag,0,sizeof(Flag));
	scanf("%d %d %d",&H,&W,&N);
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			//printf("%d %d ",i,j);
			cin >> MAP[i][j];
			//printf("Q");
			if(MAP[i][j] == 'S'){
				ba.x = j;
				ba.y = i;
				ba.c = 0;
				Flag[i][j] = 1;
				Q.push(ba);
				//printf("Sin\n");
			}
			for(int ii=0;ii<9;ii++){
				if(MAP[i][j] == Cheese[ii]){

					X[ii] = j;
					Y[ii] = i;
					//printf("\n@@@\n");
				}
			}
		}
	}
	//printf("S %d %d\n",ba.x,ba.y);
	//for(int ii=0;ii<2;ii++)
	//printf("%d %d\n",X[0],Y[0]);
	while(!Q.empty()){
		//printf("QA\n");
		ba = Q.front();
		Q.pop();
		if(ba.x==X[Nc] && ba.y==Y[Nc]){
			//printf("OZA");
			Nc++;
			memset(Flag,0,sizeof(Flag));
			while(!Q.empty()){
				Q.pop();
			}
			Q.push(ba);
		}
		//printf("aaa\n");
		if(Nc == N) break;
		for(int i=0;i<4;i++){
			if(MAP[ba.y+mv[i][1]][ba.x+mv[i][0]]!='X' && Flag[ba.y+mv[i][1]][ba.x+mv[i][0]]==0 && (ba.x+mv[i][0])>=0&&(ba.x+mv[i][0])<W&&(ba.y+mv[i][1])>=0&&(ba.y+mv[i][1])<H){
				v.x=ba.x+mv[i][0];
				v.y=ba.y+mv[i][1];
				v.c=ba.c+1;
				Q.push(v);
				Flag[v.y][v.x] = 1;
				//printf("%d %d\n",v.x,v.y);
			}
		}
	}
	cout <<ba.c<<endl
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:77:26: error: expected ';' before 'return'
   77 |         cout <<ba.c<<endl
      |                          ^
      |                          ;
   78 |         return 0;
      |         ~~~~~~