Language: C++

int main() {
    int H, W;
    cin >> H >> W;

    string S[H];
    int wnum = 0;

    for (int i = 0; i < H; i++) {
        cin >> S[i];
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '.') wnum++;
        }
    }

    int INF = 1 << 30;
    vector<vector<int>> d(H, vector<int>(W, INF));

    queue<pair<int, int>> q;

    d[0][0] = 1;
    q.push({0, 0});

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

    while (!q.empty()) {
        pair<int, int> p = q.front();
        int x = p.first;
        int y = p.second;

        q.pop();

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];

            if (nx >= 0 && nx < H && ny >= 0 && ny < W) {
                if (S[nx][ny] == '.' && d[x][y] + 1 < d[nx][ny]) {
                    d[nx][ny] = d[x][y] + 1;
                    q.push({nx, ny});
                }
            }
        }
    }

    if (d[H - 1][W - 1] == INF) {
        // 訪れなかった=ゴール不可能
        cout << -1 << endl;
    } else {
        cout << wnum - d[H - 1][W - 1] << endl;
    }

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:3:5: error: 'cin' was not declared in this scope
    3 |     cin >> H >> W;
      |     ^~~
a.cc:5:5: error: 'string' was not declared in this scope
    5 |     string S[H];
      |     ^~~~~~
a.cc:9:16: error: 'S' was not declared in this scope
    9 |         cin >> S[i];
      |                ^
a.cc:16:5: error: 'vector' was not declared in this scope
   16 |     vector<vector<int>> d(H, vector<int>(W, INF));
      |     ^~~~~~
a.cc:16:19: error: expected primary-expression before 'int'
   16 |     vector<vector<int>> d(H, vector<int>(W, INF));
      |                   ^~~
a.cc:18:5: error: 'queue' was not declared in this scope
   18 |     queue<pair<int, int>> q;
      |     ^~~~~
a.cc:18:11: error: 'pair' was not declared in this scope
   18 |     queue<pair<int, int>> q;
      |           ^~~~
a.cc:18:16: error: expected primary-expression before 'int'
   18 |     queue<pair<int, int>> q;
      |                ^~~
a.cc:20:5: error: 'd' was not declared in this scope
   20 |     d[0][0] = 1;
      |     ^
a.cc:21:5: error: 'q' was not declared in this scope
   21 |     q.push({0, 0});
      |     ^
a.cc:27:14: error: expected primary-expression before 'int'
   27 |         pair<int, int> p = q.front();
      |              ^~~
a.cc:28:17: error: 'p' was not declared in this scope
   28 |         int x = p.first;
      |                 ^
a.cc:38:21: error: 'S' was not declared in this scope
   38 |                 if (S[nx][ny] == '.' && d[x][y] + 1 < d[nx][ny]) {
      |                     ^
a.cc:48:9: error: 'cout' was not declared in this scope
   48 |         cout << -1 << endl;
      |         ^~~~
a.cc:48:23: error: 'endl' was not declared in this scope
   48 |         cout << -1 << endl;
      |                       ^~~~
a.cc:50:9: error: 'cout' was not declared in this scope
   50 |         cout << wnum - d[H - 1][W - 1] << endl;
      |         ^~~~
a.cc:50:43: error: 'endl' was not declared in this scope
   50 |         cout << wnum - d[H - 1][W - 1] << endl;
      |                                           ^~~~