Language: C++

#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;
const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

using namespace std;

int H, W;
char A[1001][1001];
int d[1001][1001];
bool check[1001][1001];
int maximum;

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

typedef pair<int, int> P;

bool is_in_map(int y, int x) {
	if (y < 0 || y >= H || x<0 || x >= W) {
		return false;
	}
	return true;
}

int dfs(int y, int x)
{
	check[y][x] = true;

	if (A[y][x] == '#') {
		d[y][x] = 0;
		return 0;
	}

	FOR(k, 0, 4) {
		int ny = y + dy[k];
		int nx = x + dx[k];
		if (is_in_map(ny, nx) && (check[ny][nx] == false)) {
			d[y][x] = min(d[y][x], dfs(ny, nx) + 1);
		}
	}
	if(maximum < d[y][x])
		maximum = d[y][x];
}

int main(void)
{
	vector<P> black;
	cin >> H >> W;
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			cin >> A[i][j];
			if (A[i][j] == '#') {
				black.push_back(P(i, j));
			}
		}
	}

	fill(d, d + H * W, INF);
	fill(check, check + H * W, false);

	maximum = 0;
	dfs(0, 0);

	cout << maximum << endl;

	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[1001]; _Tp = int; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int (*)[1001]; _Tp = int]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[1001]; _Tp = int]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:71:6:   required from here
   71 |         fill(d, d + H * W, INF);
      |         ~~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const int' to 'int [1001]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = bool (*)[1001]; _Tp = bool; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = bool (*)[1001]; _Tp = bool]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1029:20:   required from 'void std::fill(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = bool (*)[1001]; _Tp = bool]'
 1029 |       std::__fill_a(__first, __last, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:72:6:   required from here
   72 |         fill(check, check + H * W, false);
      |         ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const bool' to 'bool [1001]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~
a.cc: In function 'int dfs(int, int)':
a.cc:56:1: warning: control reaches end of non-void function [-Wreturn-type]
   56 | }
      | ^