Language: C++

#include <bits/stdc++.h>
using namespace std;


#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}


const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};







int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W; cin >> H >> W;
    vector<string> field(H);
    rep(i,H) cin >> field[i];
    
    bool seen[H][W];
    memset( seen, false, sizeof(seen) );
    
    int countsharp = 0;
    
    rep(i,H){
        rep(j,W){
            if(field[i][j]=='#') {
                seen[i][j] = true;
                countsharp++;
            }
        }
    }
    seen[0][0] = true;
    
    queue<pair<int, int>> que{};
    int dist[H][W];
    memset( dist, -1, sizeof(dist));
    
    que.push(make_pair(0, 0));
    dist[0][0] = 0;
    
    while(!que.empty()){
        
        
        int nowh = que.front().first;
        int noww = que.front().second;
        
        que.pop();
        
        
        
        
        for (int i = 0; i < 4; i++) {
            
            int newh = nowh + dx4[i];
            int neww = noww + dy4[i];
            if( !(0<=newh&&newh<H && 0<=neww&&neww<W) ) continue;
            if( seen[newh][neww] ) continue;
            
            que.push(make_pair(newh,neww));
            dist[newh][neww] = dist[nowh][noww] + 1;
            seen[newh][neww] = true;
        }
        
        
        
        
    }
    
    if(seen[H-1][W-1]){
        cout << H*W - countsharp - dist[H-1][W-1] - 1 << endl;
    }else{
        cout << -1 << endl;
    }
    
    
    
    
    
}



Compiler output:
a.cc: In function 'std::ostream& operator<<(std::ostream&, const std::vector<_Tp>&)':
a.cc:5:25: error: 'll' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                         ^~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:13:5: note: in expansion of macro 'REP'
   13 |     REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
      |     ^~~
a.cc:13:9: error: 'i' was not declared in this scope
   13 |     REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
      |         ^
a.cc:5:49: note: in definition of macro 'FOR'
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                 ^
a.cc:13:5: note: in expansion of macro 'REP'
   13 |     REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
      |     ^~~
a.cc:5:51: error: '__last_i' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                   ^~~~~~~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:13:5: note: in expansion of macro 'REP'
   13 |     REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
      |     ^~~
a.cc: In function 'std::ostream& operator<<(std::ostream&, const std::vector<std::vector<_Tp> >&)':
a.cc:5:25: error: 'll' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                         ^~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:15:5: note: in expansion of macro 'REP'
   15 |     REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
      |     ^~~
a.cc:15:9: error: 'i' was not declared in this scope
   15 |     REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
      |         ^
a.cc:5:49: note: in definition of macro 'FOR'
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                 ^
a.cc:15:5: note: in expansion of macro 'REP'
   15 |     REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
      |     ^~~
a.cc:5:51: error: '__last_i' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                   ^~~~~~~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:15:5: note: in expansion of macro 'REP'
   15 |     REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}
      |     ^~~
a.cc: In function 'int main(int, const char**)':
a.cc:5:25: error: 'll' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                         ^~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:10:18: note: in expansion of macro '__GET_MACRO3'
   10 | #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
      |                  ^~~~~~~~~~~~
a.cc:38:5: note: in expansion of macro 'rep'
   38 |     rep(i,H) cin >> field[i];
      |     ^~~
a.cc:38:9: error: 'i' was not declared in this scope
   38 |     rep(i,H) cin >> field[i];
      |         ^
a.cc:5:49: note: in definition of macro 'FOR'
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                 ^
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:38:5: note: in expansion of macro 'rep'
   38 |     rep(i,H) cin >> field[i];
      |     ^~~
a.cc:5:51: error: '__last_i' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                   ^~~~~~~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:10:18: note: in expansion of macro '__GET_MACRO3'
   10 | #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
      |                  ^~~~~~~~~~~~
a.cc:38:5: note: in expansion of macro 'rep'
   38 |     rep(i,H) cin >> field[i];
      |     ^~~
a.cc:5:25: error: 'll' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                         ^~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:10:18: note: in expansion of macro '__GET_MACRO3'
   10 | #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
      |                  ^~~~~~~~~~~~
a.cc:45:5: note: in expansion of macro 'rep'
   45 |     rep(i,H){
      |     ^~~
a.cc:45:9: error: 'i' was not declared in this scope
   45 |     rep(i,H){
      |         ^
a.cc:5:49: note: in definition of macro 'FOR'
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                 ^
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:45:5: note: in expansion of macro 'rep'
   45 |     rep(i,H){
      |     ^~~
a.cc:5:51: error: '__last_i' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                   ^~~~~~~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:10:18: note: in expansion of macro '__GET_MACRO3'
   10 | #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
      |                  ^~~~~~~~~~~~
a.cc:45:5: note: in expansion of macro 'rep'
   45 |     rep(i,H){
      |     ^~~
a.cc:46:13: error: expected ';' before 'j'
   46 |         rep(j,W){
      |             ^
a.cc:5:28: note: in definition of macro 'FOR'
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                            ^
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:46:9: note: in expansion of macro 'rep'
   46 |         rep(j,W){
      |         ^~~
a.cc:46:13: error: 'j' was not declared in this scope
   46 |         rep(j,W){
      |             ^
a.cc:5:49: note: in definition of macro 'FOR'
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                 ^
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:46:9: note: in expansion of macro 'rep'
   46 |         rep(j,W){
      |         ^~~
a.cc:5:51: error: '__last_j' was not declared in this scope
    5 | #define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
      |                                                   ^~~~~~~
a.cc:7:18: note: in expansion of macro 'FOR'
    7 | #define REP(i,n) FOR(i,0,n)
      |                  ^~~
a.cc:9:45: note: in expansion of macro 'REP'
    9 | #define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
      |                                             ^~~~
a.cc:10:18: note: in expansion of macro '__GET_MACRO3'
   10 | #define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
      |                  ^~~~~~~~~~~~
a.cc:46:9: note: in expansion of macro 'rep'
   46 |         rep(j,W){
      |         ^~~