Language: C++



using namespace std;

#define fi first
#define se second

const ll maxn = 1e3 + 10;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
char mp[maxn][maxn];
int step[maxn][maxn];
bool vis[maxn][maxn];
int n,m;

bool check(int x,int y) {
if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
return true;
}

int BFS() {
queue<pair<int ,int> > q;
q.push(make_pair(0,0));
step[0][0] = 1;
vis[0][0] = true;
while (!q.empty()) {
pair<int ,int> t = q.front();
q.pop();
for(int i = 0;i < 4;i++) {
int tox = t.fi + Move[i][0];
int toy = t.se + Move[i][1];
if(tox == n - 1 && toy == m - 1) return step[t.fi][t.se] + 1;
if(check(tox,toy)) {
vis[tox][toy] = true;
step[tox][toy] = step[t.fi][t.se] + 1;
q.push(make_pair(tox,toy));
}
}
}
return -1;
}


int main(){
init();
cin>>n>>m;
int cnt = 0;
for(int i = 0;i < n;i++)
for(int j = 0;j < m;j++) {
cin>>mp[i][j];
if(mp[i][j] == '#') cnt++;
}
int res = BFS();
if(res == -1) {
cout<<"-1"<<endl;
} else {
cout<<nm - res - cnt<<endl;
}
return 0;
}

Compiler output:
a.cc:8:7: error: 'll' does not name a type
    8 | const ll maxn = 1e3 + 10;
      |       ^~
a.cc:10:9: error: 'maxn' was not declared in this scope
   10 | char mp[maxn][maxn];
      |         ^~~~
a.cc:10:15: error: 'maxn' was not declared in this scope
   10 | char mp[maxn][maxn];
      |               ^~~~
a.cc:11:10: error: 'maxn' was not declared in this scope
   11 | int step[maxn][maxn];
      |          ^~~~
a.cc:11:16: error: 'maxn' was not declared in this scope
   11 | int step[maxn][maxn];
      |                ^~~~
a.cc:12:10: error: 'maxn' was not declared in this scope
   12 | bool vis[maxn][maxn];
      |          ^~~~
a.cc:12:16: error: 'maxn' was not declared in this scope
   12 | bool vis[maxn][maxn];
      |                ^~~~
a.cc: In function 'bool check(int, int)':
a.cc:16:41: error: 'vis' was not declared in this scope
   16 | if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
      |                                         ^~~
a.cc:16:54: error: 'mp' was not declared in this scope; did you mean 'm'?
   16 | if(x < 0 || y < 0|| x >= n || y >= m || vis[x][y] || mp[x][y] == '#') return false;
      |                                                      ^~
      |                                                      m
a.cc: In function 'int BFS()':
a.cc:21:1: error: 'queue' was not declared in this scope
   21 | queue<pair<int ,int> > q;
      | ^~~~~
a.cc:1:1: note: 'std::queue' is defined in header '<queue>'; this is probably fixable by adding '#include <queue>'
  +++ |+#include <queue>
    1 | 
a.cc:21:7: error: 'pair' was not declared in this scope
   21 | queue<pair<int ,int> > q;
      |       ^~~~
a.cc:1:1: note: 'std::pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
  +++ |+#include <utility>
    1 | 
a.cc:21:12: error: expected primary-expression before 'int'
   21 | queue<pair<int ,int> > q;
      |            ^~~
a.cc:22:1: error: 'q' was not declared in this scope
   22 | q.push(make_pair(0,0));
      | ^
a.cc:22:8: error: 'make_pair' was not declared in this scope
   22 | q.push(make_pair(0,0));
      |        ^~~~~~~~~
a.cc:22:8: note: 'std::make_pair' is defined in header '<utility>'; this is probably fixable by adding '#include <utility>'
a.cc:23:1: error: 'step' was not declared in this scope
   23 | step[0][0] = 1;
      | ^~~~
a.cc:24:1: error: 'vis' was not declared in this scope
   24 | vis[0][0] = true;
      | ^~~
a.cc:26:6: error: expected primary-expression before 'int'
   26 | pair<int ,int> t = q.front();
      |      ^~~
a.cc:29:11: error: 't' was not declared in this scope
   29 | int tox = t.fi + Move[i][0];
      |           ^
a.cc: In function 'int main()':
a.cc:44:1: error: 'init' was not declared in this scope; did you mean 'int'?
   44 | init();
      | ^~~~
      | int
a.cc:45:1: error: 'cin' was not declared in this scope
   45 | cin>>n>>m;
      | ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | 
a.cc:49:6: error: 'mp' was not declared in this scope; did you mean 'm'?
   49 | cin>>mp[i][j];
      |      ^~
      |      m
a.cc:54:1: error: 'cout' was not declared in this scope
   54 | cout<<"-1"<<endl;
      | ^~~~
a.cc:54:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:54:13: error: 'endl' was not declared in this scope
   54 | cout<<"-1"<<endl;
      |             ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | 
a.cc:56:1: error: 'cout' was not declared in this scope
   56 | cout<<nm - res - cnt<<endl;
      | ^~~~
a.cc:56:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:56:7: error: 'nm' was not declared in this scope; did you mean 'n'?
   56 | cout<<nm - res - cnt<<endl;
      |       ^~
      |       n
a.cc:56:23: error: 'endl' was not declared in this scope
   56 | cout<<nm - res - cnt<<endl;
      |                       ^~~~
a.cc:56:23: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'