Language: C++


typedef pair<int, int> P;
#include<algorithm>
#include<iostream>
#include<cmath>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
const int INF = 100000000;
char maze[51][51];
int d[50][50];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

int bfs(int H,int W) {
	int i, j, k, l, m, nx, ny;
	queue<P> que;
	for (i = 0; i < 50; i++) {
		for (j = 0; j < 50; j++) {
			d[i][j] = INF;
		}
	}
	que.push(P(0, 0));
	d[0][0] = 0;
	while (que.size()) {
		P p = que.front();
		que.pop();
		if (p.first == 49 && p.second == 49)
			break;
		for (i = 0; i < 4; i++) {
			nx = p.first + d[x];
			ny = p.second + d[y];

			if (nx >= 0 && nx < H&&ny >= 0 && ny < W&&d[nx][ny] == INF && maze[nx][ny] != '#') {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
	return d[W-1][H-1];
}



int main()
{
	int H, W;
	cin >> H >> W;
	int i, j, k;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			cin >> maze[i][j];
		}
	}
	k = bfs(H, W);
	if (k = INF)
		cout << "-1" << endl;
	else
		cout << H * W - k << endl;
    return 0;
}



Compiler output:
a.cc:2:9: error: 'pair' does not name a type
    2 | typedef pair<int, int> P;
      |         ^~~~
a.cc: In function 'int bfs(int, int)':
a.cc:18:9: error: 'queue' was not declared in this scope
   18 |         queue<P> que;
      |         ^~~~~
a.cc:18:15: error: 'P' was not declared in this scope
   18 |         queue<P> que;
      |               ^
a.cc:18:18: error: 'que' was not declared in this scope
   18 |         queue<P> que;
      |                  ^~~
a.cc:27:18: error: expected ';' before 'p'
   27 |                 P p = que.front();
      |                  ^~
      |                  ;
a.cc:29:21: error: 'p' was not declared in this scope
   29 |                 if (p.first == 49 && p.second == 49)
      |                     ^
a.cc:32:30: error: 'p' was not declared in this scope
   32 |                         nx = p.first + d[x];
      |                              ^
a.cc:32:42: error: 'x' was not declared in this scope; did you mean 'nx'?
   32 |                         nx = p.first + d[x];
      |                                          ^
      |                                          nx
a.cc:33:43: error: 'y' was not declared in this scope; did you mean 'ny'?
   33 |                         ny = p.second + d[y];
      |                                           ^
      |                                           ny
a.cc: In function 'int main()':
a.cc:49:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   49 |         cin >> H >> W;
      |         ^~~
      |         std::cin
In file included from a.cc:4:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:58:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   58 |                 cout << "-1" << endl;
      |                 ^~~~
      |                 std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:58:33: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   58 |                 cout << "-1" << endl;
      |                                 ^~~~
      |                                 std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~
a.cc:60:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   60 |                 cout << H * W - k << endl;
      |                 ^~~~
      |                 std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:60:38: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   60 |                 cout << H * W - k << endl;
      |                                      ^~~~
      |                                      std::endl
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~