Language: C++


#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
typedef pair<int, int> P;
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:12:9: error: 'pair' does not name a type
   12 | typedef pair<int, int> P;
      |         ^~~~
a.cc: In function 'int bfs(int, int)':
a.cc:21:9: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
   21 |         queue<P> que;
      |         ^~~~~
      |         std::queue
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:5:
/usr/include/c++/14/bits/stl_queue.h:96:11: note: 'std::queue' declared here
   96 |     class queue
      |           ^~~~~
a.cc:21:15: error: 'P' was not declared in this scope
   21 |         queue<P> que;
      |               ^
a.cc:21:18: error: 'que' was not declared in this scope
   21 |         queue<P> que;
      |                  ^~~
a.cc:30:18: error: expected ';' before 'p'
   30 |                 P p = que.front();
      |                  ^~
      |                  ;
a.cc:32:21: error: 'p' was not declared in this scope
   32 |                 if (p.first == 49 && p.second == 49)
      |                     ^
a.cc:35:30: error: 'p' was not declared in this scope
   35 |                         nx = p.first + d[x];
      |                              ^
a.cc:35:42: error: 'x' was not declared in this scope; did you mean 'nx'?
   35 |                         nx = p.first + d[x];
      |                                          ^
      |                                          nx
a.cc:36:43: error: 'y' was not declared in this scope; did you mean 'ny'?
   36 |                         ny = p.second + d[y];
      |                                           ^
      |                                           ny
a.cc: In function 'int main()':
a.cc:52:9: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   52 |         cin >> H >> W;
      |         ^~~
      |         std::cin
In file included from a.cc:2:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:61:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   61 |                 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:61:33: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   61 |                 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:63:17: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   63 |                 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:63:38: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   63 |                 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)
      |     ^~~~