Language: C++

#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main() {
  int H,W;
  cin >> H >> W;
  v(v(char)) M(H,v(char)(W));
  rep(i,H) {
    rep(j,W) {
      cin >> M[i][j];
    }
    
  }
  //pair<int,P> ls;
  vector<pair<P,P>> wRank;
  vector<pair<P,P>> hRank;
  rep(i,H) {
    int start = INF;
    rep(j,W) {
      if(M[i][j] == '#') {
        if(start == INF) continue;
        wRank.emplace_back(make_pair(P(j-1-start,i),P(start,j-1)));
        start = INF;
      } else {
        if(start == INF) start = j;
      }
    }
    if(start != INF) wRank.emplace_back(make_pair(P(W-1-start,i),P(start,W-1)));
  }
  rep(i,W) {
    int start = INF;
    rep(j,H) {
      if(M[j][i] == '#') {
        if(start == INF) continue;
        hRank.emplace_back(make_pair(i,P(start,j-1)));
        start = INF;
      } else {
        if(start == INF) start = j;
      }
    }
    if(start != INF) hRank.emplace_back(make_pair(P(H-1-start,i),P(start,H-1)));
  }
  sort(rng(wRank));
  sort(rng(hRank));
  reverse(rng(wRank));
  reverse(rng(hRank));
  /*
  rep(i,sz(wRank)) {
    show(wRank[i].first);
    show(wRank[i].second.first);
    show(wRank[i].second.second);
  }*/
  int ans = -INF;
  rep(i,sz(wRank)) {
    rep(j,sz(hRank)) {
      int a = wRank[i].first.second;
      int al = wRank[i].second.first;
      int ar = wRank[i].second.second;
      int b = hRank[j].first.second;
      int bl = hRank[j].second.first;
      int br = hRank[j].second.second;
      if(a >=bl &&a <= br && b >= al && b <= br) {
          ans = max(ans,ar-al+br-bl);
      }
    }
  }
  cout << ans+1 << endl;
  return 0;
}

Compiler output:
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/c++allocator.h:33,
                 from /usr/include/c++/14/bits/allocator.h:46,
                 from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/new_allocator.h: In instantiation of 'void std::__new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::pair<std::pair<int, int>, std::pair<int, int> >; _Args = {std::pair<int, std::pair<int, int> >}; _Tp = std::pair<std::pair<int, int>, std::pair<int, int> >]':
/usr/include/c++/14/bits/alloc_traits.h:575:17:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(allocator_type&, _Up*, _Args&& ...) [with _Up = std::pair<std::pair<int, int>, std::pair<int, int> >; _Args = {std::pair<int, std::pair<int, int> >}; _Tp = std::pair<std::pair<int, int>, std::pair<int, int> >; allocator_type = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >]'
  575 |           __a.construct(__p, std::forward<_Args>(__args)...);
      |           ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/vector.tcc:117:30:   required from 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::pair<int, std::pair<int, int> >}; _Tp = std::pair<std::pair<int, int>, std::pair<int, int> >; _Alloc = std::allocator<std::pair<std::pair<int, int>, std::pair<int, int> > >; reference = std::pair<std::pair<int, int>, std::pair<int, int> >&]'
  117 |             _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118 |                                      std::forward<_Args>(__args)...);
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:75:27:   required from here
   75 |         hRank.emplace_back(make_pair(i,P(start,j-1)));
      |         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/new_allocator.h:191:11: error: no matching function for call to 'std::pair<std::pair<int, int>, std::pair<int, int> >::pair(std::pair<int, std::pair<int, int> >)'
  191 |         { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_pair.h:913:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  913 |         explicit constexpr pair(pair<_U1, _U2>&& __p)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:913:28: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:912:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  912 |                          bool>::type=false>
      |                                      ^~~~~
/usr/include/c++/14/bits/stl_pair.h:902:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<std::pair<int, int>, _U1>::value) || (! std::is_same<std::pair<int, int>, _U2>::value)), std::pair<int, int>, std::pair<int, int> >::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(std::pair<_U1, _U2>&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<((! std::is_same<_T1, _U1>::value) || (! std::is_same<_T2, _U2>::value)), _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  902 |         constexpr pair(pair<_U1, _U2>&& __p)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:902:19: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_pair.h:901:38: error: no type named 'type' in 'struct std::enable_if<false, bool>'
  901 |                          bool>::type=true>
      |                                      ^~~~
/usr/include/c++/14/bits/stl_pair.h:891:28: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && (! _ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && (! std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>())), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  891 |         explicit constexpr pair(_U1&& __x, _U2&& __y)
      |                            ^~~~
/usr/include/c++/14/bits/stl_pair.h:891:28: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:881:19: note: candidate: 'template<class _U1, class _U2, typename std::enable_if<(_MoveConstructiblePair<_U1, _U2>() && _ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U2 = _U1; typename std::enable_if<(std::_PCC<true, _T1, _T2>::_MoveConstructiblePair<_U1, _U2>() && std::_PCC<true, _T1, _T2>::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  881 |         constexpr pair(_U1&& __x, _U2&& __y)
      |                   ^~~~
/usr/include/c++/14/bits/stl_pair.h:881:19: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:869:9: note: candidate: 'template<class _U2, typename std::enable_if<std::__and_<std::is_pointer<std::pair<int, int> >, std::__not_<std::is_reference<_Tp> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::__not_<std::is_convertible<_U1, std::pair<int, int> > > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(__zero_as_null_pointer_constant, _U2&&, ...) [with typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U1> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::__not_<std::is_convertible<_U2, _T2> > >::value, bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  869 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:869:9: note:   candidate expects at least 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:856:9: note: candidate: 'template<class _U2, typename std::enable_if<std::__and_<std::is_pointer<std::pair<int, int> >, std::__not_<std::is_reference<_Tp> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::is_convertible<_U1, std::pair<int, int> > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(__zero_as_null_pointer_constant, _U2&&, ...) [with typename std::enable_if<std::__and_<std::is_pointer<_Tp>, std::__not_<std::is_reference<_U1> >, std::is_constructible<_T2, _U2>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::is_convertible<_U2, _T2> >::value, bool>::type <anonymous> = _U2; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  856 |         pair(__zero_as_null_pointer_constant, _U2&& __y, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:856:9: note:   candidate expects at least 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:843:9: note: candidate: 'template<class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_Tp> >, std::is_pointer<std::pair<int, int> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_constructible<std::pair<int, int>, const _U1&> >, std::__not_<std::is_convertible<_U1, std::pair<int, int> > > >::value, bool>::type <anonymous> > constexpr std::pair<_T1, _T2>::pair(_U1&&, __zero_as_null_pointer_constant, ...) [with typename std::enable_if<std::__and_<std::__not_<std::is_reference<_U1> >, std::is_pointer<_T2>, std::is_constructible<_T1, _U1>, std::__not_<std::is_constructible<_T1, const _U1&> >, std::__not_<std::is_convertible<_U1, _T1> > >::value, bool>::type <anonymous> = _U1; _T1 = std::pair<int, int>; _T2 = std::pair<int, int>]'
  843 |         pair(_U1&& __x, __zero_as_null_pointer_constant, ...)
      |         ^~~~
/usr/include/c++/14/bits/stl_pair.h:843:9: note:   candidate expects at least 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_pair.h:830:9: note: candidate: 'template<class _U1, typename std::enable_if<std::__and_<std::__not_<std::is_reference<_Tp> >, std::is_pointer<std::pair<int, int> >, std::is_constructible<std::pair<int, int>, _U1>, std::__not_<std::is_c