Language: C++

#include <algorithm>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define all(c) c.begin(), c.end()
#define repeat(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define debug(x) #x << "=" << (x)
#define dump(x) cerr << debug(x) << " (L:" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long> vl;
typedef vector<vector<long>> vvl;
typedef vector<string> vs;

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec)
{
    os << "[";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << ",";
    }
    os << "]";
    return os;
}

template <typename T>
T input()
{
    T t;
    cin >> t;
    return t;
}

template <typename T>
vector<T> input(const int N)
{
    vector<T> v(N);
    repeat(i, N) cin >> v[i];
    return v;
}

long long gcd(long long a, long long b)
{
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

long long lcm(long long a, long long b)
{
    return (a / gcd(a, b)) * b;
}

long long mul(const long long& a, const long long& b, const long long& mod)
{
    return ((a % mod) * (b % mod)) % mod;
}

long long power(const long long& x, const long long& y, const long long& mod)
{
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else {
        long long value = power(x, y / 2, mod);
        if (y % 2 == 0) {
            return mul(value, value, mod);
        } else {
            return mul(value, value, mod) * x % mod;
        }
    }
}

long long div(const long long& a, const long long& b, const long long& mod)
{
    return mul(a, power(b, mod - 2, mod), mod);
}

map<long long, long long> factorials;
long long factorial(const long long& n, const long long& mod)
{
    if (n == 0 || n == 1) {
        return 1;
    }
    if (factorials[n] != 0) {
        return factorials[n];
    }
    factorials[n] = n * factorial(n - 1, mod) % mod;
    return factorials[n] % mod;
}

long long combination(const long long& n, const long long& x, const long long& mod)
{
    long long numerator = 1;
    long long denominator = 1;
    repeat(i, x)
    {
        numerator *= (n - i) % mod;
        numerator %= mod;
        denominator *= (i + 1) % mod;
        denominator %= mod;
    }
    return div(numerator, denominator, mod);
}

int manhattanDistance(int x1, int y1, int x2, int y2)
{
    return abs(x1 - x2) + abs(y1 - y2);
}

int main()
{
    int H, W;
    cin >> H >> W;
    vs field(H);
    vi rows();
    vi columns();

    repeat(i, H) cin >> field[i];
    for (int i = 0; i < H; ++i) {
        auto row = field[i];
        for (int j = 0; j < W; ++j) {
            if (row[j] == '#') {
                rows.push_back(i);
                columns.push_back(j);
            }
        }
    }
    auto result = H * W;
    for (int k = 0; k < rows.size(); ++k) {
        auto tmp_x_max = 0;
        for (int i = 0; i < H; ++i) {
            auto tmp = abs(rows[k] - i);
            if (tmp_x_max < tmp) {
                tmp_x_max = tmp;
            }
        }
        auto tmp_y_max = 0;
        for (int i = 0; i < W; ++i) {
            auto tmp = abs(columns[k] - i);
            if (tmp_y_max < tmp) {
                tmp_y_max = tmp;
            }
        }
        auto dist = manhattanDistance(tmp_x_max, tmp_y_max, rows[k], columns[k]);
        if (dist < result) {
            result = dist;
        }
    }
    cout << result << endl;
    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:142:12: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  142 |     vi rows();
      |            ^~
a.cc:143:15: warning: empty parentheses were disambiguated as a function declaration [-Wvexing-parse]
  143 |     vi columns();
      |               ^~
a.cc:150:22: error: request for member 'push_back' in 'rows', which is of non-class type 'vi()' {aka 'std::vector<int>()'}
  150 |                 rows.push_back(i);
      |                      ^~~~~~~~~
a.cc:151:25: error: request for member 'push_back' in 'columns', which is of non-class type 'vi()' {aka 'std::vector<int>()'}
  151 |                 columns.push_back(j);
      |                         ^~~~~~~~~
a.cc:156:30: error: request for member 'size' in 'rows', which is of non-class type 'vi()' {aka 'std::vector<int>()'}
  156 |     for (int k = 0; k < rows.size(); ++k) {
      |                              ^~~~
a.cc:159:34: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  159 |             auto tmp = abs(rows[k] - i);
      |                                  ^
a.cc:159:36: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  159 |             auto tmp = abs(rows[k] - i);
      |                            ~~~~~~~~^~~
a.cc:159:27: error: no matching function for call to 'abs(vi (*)())'
  159 |             auto tmp = abs(rows[k] - i);
      |                        ~~~^~~~~~~~~~~~~
In file included from /usr/include/c++/14/cstdlib:79,
                 from /usr/include/c++/14/bits/stl_algo.h:71,
                 from /usr/include/c++/14/algorithm:61,
                 from a.cc:1:
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)' (near match)
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/stdlib.h:980:12: note:   conversion of argument 1 would be ill-formed:
a.cc:159:36: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'int' [-fpermissive]
  159 |             auto tmp = abs(rows[k] - i);
      |                            ~~~~~~~~^~~
      |                                    |
      |                                    vi (*)() {aka std::vector<int> (*)()}
In file included from /usr/include/c++/14/cstdlib:81:
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)' (near match)
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note:   conversion of argument 1 would be ill-formed:
a.cc:159:36: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to '__int128' [-fpermissive]
  159 |             auto tmp = abs(rows[k] - i);
      |                            ~~~~~~~~^~~
      |                                    |
      |                                    vi (*)() {aka std::vector<int> (*)()}
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)' (near match)
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note:   conversion of argument 1 would be ill-formed:
a.cc:159:36: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'long long int' [-fpermissive]
  159 |             auto tmp = abs(rows[k] - i);
      |                            ~~~~~~~~^~~
      |                                    |
      |                                    vi (*)() {aka std::vector<int> (*)()}
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)' (near match)
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note:   conversion of argument 1 would be ill-formed:
a.cc:159:36: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'long int' [-fpermissive]
  159 |             auto tmp = abs(rows[k] - i);
      |                            ~~~~~~~~^~~
      |                                    |
      |                                    vi (*)() {aka std::vector<int> (*)()}
In file included from /usr/include/c++/14/valarray:605,
                 from a.cc:16:
/usr/include/c++/14/bits/valarray_after.h:445:5: note: candidate: 'template<class _Tp> std::_Expr<std::__detail::_UnClos<std::_Abs, std::_ValArray, _Tp>, _Tp> std::abs(const valarray<_Tp>&)'
  445 |     _DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note:   template argument deduction/substitution failed:
a.cc:159:27: note:   mismatched types 'const std::valarray<_Tp>' and 'vi (*)()' {aka 'std::vector<int> (*)()'}
  159 |             auto tmp = abs(rows[k] - i);
      |                        ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note: candidate: 'template<class _Dom> std::_Expr<std::__detail::_UnClos<std::_Abs, std::_Expr, _Dom>, typename _Dom::value_type> std::abs(const _Expr<_Dom1, typename _Dom1::value_type>&)'
  445 |     _DEFINE_EXPR_UNARY_FUNCTION(abs, struct std::_Abs)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/valarray_after.h:445:5: note:   template argument deduction/substitution failed:
a.cc:159:27: note:   mismatched types 'const std::_Expr<_Dom1, typename _Dom1::value_type>' and 'vi (*)()' {aka 'std::vector<int> (*)()'}
  159 |             auto tmp = abs(rows[k] - i);
      |                        ~~~^~~~~~~~~~~~~
In file included from a.cc:3:
/usr/include/c++/14/complex:892:5: note: candidate: 'template<class _Tp> _Tp std::abs(const complex<_Tp>&)'
  892 |     abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
      |     ^~~
/usr/include/c++/14/complex:892:5: note:   template argument deduction/substitution failed:
a.cc:159:27: note:   mismatched types 'const std::complex<_Tp>' and 'vi (*)()' {aka 'std::vector<int> (*)()'}
  159 |             auto tmp = abs(rows[k] - i);
      |                        ~~~^~~~~~~~~~~~~
/usr/include/c++/14/bits/std_abs.h:137:3: note: candidate: 'constexpr __float128 std::abs(__float128)'
  137 |   abs(__float128 __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:137:18: note:   no known conversion for argument 1 from 'vi (*)()' {aka 'std::vector<int> (*)()'} to '__float128'
  137 |   abs(__float128 __x)
      |       ~~~~~~~~~~~^~~
/usr/include/c++/14/bits/std_abs.h:79:3: note: candidate: 'constexpr long double std::abs(long double)'
   79 |   abs(long double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:79:19: note:   no known conversion for argument 1 from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'long double'
   79 |   abs(long double __x)
      |       ~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/std_abs.h:75:3: note: candidate: 'constexpr float std::abs(float)'
   75 |   abs(float __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:75:13: note:   no known conversion for argument 1 from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'float'
   75 |   abs(float __x)
      |       ~~~~~~^~~
/usr/include/c++/14/bits/std_abs.h:71:3: note: candidate: 'constexpr double std::abs(double)'
   71 |   abs(double __x)
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:71:14: note:   no known conversion for argument 1 from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'double'
   71 |   abs(double __x)
      |       ~~~~~~~^~~
a.cc:166:37: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  166 |             auto tmp = abs(columns[k] - i);
      |                                     ^
a.cc:166:39: warning: pointer to a function used in arithmetic [-Wpointer-arith]
  166 |             auto tmp = abs(columns[k] - i);
      |                            ~~~~~~~~~~~^~~
a.cc:166:27: error: no matching function for call to 'abs(vi (*)())'
  166 |             auto tmp = abs(columns[k] - i);
      |                        ~~~^~~~~~~~~~~~~~~~
/usr/include/stdlib.h:980:12: note: candidate: 'int abs(int)' (near match)
  980 | extern int abs (int __x) __THROW __attribute__ ((__const__)) __wur;
      |            ^~~
/usr/include/stdlib.h:980:12: note:   conversion of argument 1 would be ill-formed:
a.cc:166:39: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'int' [-fpermissive]
  166 |             auto tmp = abs(columns[k] - i);
      |                            ~~~~~~~~~~~^~~
      |                                       |
      |                                       vi (*)() {aka std::vector<int> (*)()}
/usr/include/c++/14/bits/std_abs.h:85:3: note: candidate: 'constexpr __int128 std::abs(__int128)' (near match)
   85 |   abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:85:3: note:   conversion of argument 1 would be ill-formed:
a.cc:166:39: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to '__int128' [-fpermissive]
  166 |             auto tmp = abs(columns[k] - i);
      |                            ~~~~~~~~~~~^~~
      |                                       |
      |                                       vi (*)() {aka std::vector<int> (*)()}
/usr/include/c++/14/bits/std_abs.h:61:3: note: candidate: 'long long int std::abs(long long int)' (near match)
   61 |   abs(long long __x) { return __builtin_llabs (__x); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:61:3: note:   conversion of argument 1 would be ill-formed:
a.cc:166:39: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'long long int' [-fpermissive]
  166 |             auto tmp = abs(columns[k] - i);
      |                            ~~~~~~~~~~~^~~
      |                                       |
      |                                       vi (*)() {aka std::vector<int> (*)()}
/usr/include/c++/14/bits/std_abs.h:56:3: note: candidate: 'long int std::abs(long int)' (near match)
   56 |   abs(long __i) { return __builtin_labs(__i); }
      |   ^~~
/usr/include/c++/14/bits/std_abs.h:56:3: note:   conversion of argument 1 would be ill-formed:
a.cc:166:39: error: invalid conversion from 'vi (*)()' {aka 'std::vector<int> (*)()'} to 'long