Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

vector<string> field;

vector<vector<pair<int, int>>> dist;
int dist[2010][2010][2];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int H, W;

void dfs(int _cx, int _cy, int _p, int &_sum){
  _sum += 1;
  int nx = _cx + dx[_p];
  int ny = _cy + dy[_p];

  if(nx < 0 || nx  >= W || ny < 0 || ny >= H) return;
  if(field[ny][nx] == '#') return;
  dfs(nx, ny, _p, _sum);

}

void searchY(int _x, int _y){
  int sum = 0;
  dfs(_y, _x, 1, sum);
  dfs(_y, _x, 3, sum);
  sum -= 1;
  dist[_y][_x][0] = sum;
}

void searchX(int _x, int _y){
  int sum = 0;
  dfs(_y, _x, 0, sum);
  dfs(_y, _x, 2, sum);
  sum -= 1;
  dist[_y][_x][1] = sum;
}


int main(){

  cin >> H >> W;

  field.resize(H);
  rep(i,H) cin >> field[i];

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      dist[i][j][0] = -1;   // height方向
      dist[i][j][1] = -1;   // width方向
    }
  }


  int ans = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(ans == H+W-1) continue;
      if(field[i][j] == '#') continue;
      if(i-1 == 0) searchY(j, i);
      else if(dist[i-1][j][0]!= -1 && field[i-1][j] == '.') dist[i][j][0] = dist[i-1][j][0];
      else searchY(j, i);

      if(j-1==0) searchX(j,i);
      else if(dist[i][j-1][0]!= -1  && field[i][j-1] == '.') dist[i][j][1] = dist[i][j-1][1];
      else searchX(j, i);

      int total = dist[i][j][0] + dist[i][j][1] -1;
      if(total > ans) ans = total;
    }
  }

  cout << ans << endl;

  return 0;
}


Compiler output:
a.cc:15:5: error: conflicting declaration 'int dist [2010][2010][2]'
   15 | int dist[2010][2010][2];
      |     ^~~~
a.cc:14:32: note: previous declaration as 'std::vector<std::vector<std::pair<int, int> > > dist'
   14 | vector<vector<pair<int, int>>> dist;
      |                                ^~~~
a.cc: In function 'void searchY(int, int)':
a.cc:36:15: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   36 |   dist[_y][_x][0] = sum;
      |               ^
a.cc: In function 'void searchX(int, int)':
a.cc:44:15: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   44 |   dist[_y][_x][1] = sum;
      |               ^
a.cc: In function 'int main()':
a.cc:57:17: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   57 |       dist[i][j][0] = -1;   // height方向
      |                 ^
a.cc:58:17: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   58 |       dist[i][j][1] = -1;   // width方向
      |                 ^
a.cc:69:27: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   69 |       else if(dist[i-1][j][0]!= -1 && field[i-1][j] == '.') dist[i][j][0] = dist[i-1][j][0];
      |                           ^
a.cc:69:71: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   69 |       else if(dist[i-1][j][0]!= -1 && field[i-1][j] == '.') dist[i][j][0] = dist[i-1][j][0];
      |                                                                       ^
a.cc:69:89: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   69 |       else if(dist[i-1][j][0]!= -1 && field[i-1][j] == '.') dist[i][j][0] = dist[i-1][j][0];
      |                                                                                         ^
a.cc:73:27: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   73 |       else if(dist[i][j-1][0]!= -1  && field[i][j-1] == '.') dist[i][j][1] = dist[i][j-1][1];
      |                           ^
a.cc:73:72: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   73 |       else if(dist[i][j-1][0]!= -1  && field[i][j-1] == '.') dist[i][j][1] = dist[i][j-1][1];
      |                                                                        ^
a.cc:73:90: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   73 |       else if(dist[i][j-1][0]!= -1  && field[i][j-1] == '.') dist[i][j][1] = dist[i][j-1][1];
      |                                                                                          ^
a.cc:76:29: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   76 |       int total = dist[i][j][0] + dist[i][j][1] -1;
      |                             ^
a.cc:76:45: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   76 |       int total = dist[i][j][0] + dist[i][j][1] -1;
      |                                             ^