Language: C++

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod  1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

signed main(){
  int H, W;
  char s[405][405];
  ll g[405][405];
  UnionFind uf(160005);

  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> s[i][j];
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(s[i][j] == '.') continue;
      for(int k = 0; k < 4; k++){
	int x = j + dx[k], y =i + dy[k];
	if(0 <= x && x < W && 0 <= y && y < H && s[y][x] == '.'){
	  for(int l = 0; l < 4; l++){
	    int xx = x + dx[l], yy = y + dy[l];
	    if(xx == j && yy == i) continue;
	    if(0 <= xx && xx < W && 0 <= yy && yy < H && s[yy][xx] == '#'){
	      // cerr << j << " " << i << " " << xx << " " << yy << endl;
	      uf.unite(i*W+j, yy*W+xx);
	    }
	  }
	}
      }
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(s[i][j] == '.') continue;
      for(int k = 0; k < 4; k++){
	int x = j + dx[k], y = i + dy[k];
	if(0 <= x && x < W && 0 <= y && y < H && s[y][x] == '.'){
	  int cnt = uf.size(i * W + j);
	  // cerr << cnt << endl;
	  g[y][x] = max(g[y][x], cnt);	  
	}
      }
    }
  }

  ll ans = 0;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      ans += g[i][j];
      // cerr << g[i][j];
    }// cerr <<endl;
  }
  cout << ans << endl;
  return 0;
}

/*

4 4
....
.#.#
....
...#

*/


Compiler output:
a.cc: In function 'int main()':
a.cc:117:24: error: no matching function for call to 'max(ll&, int&)'
  117 |           g[y][x] = max(g[y][x], cnt);
      |                     ~~~^~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:117:24: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
  117 |           g[y][x] = max(g[y][x], cnt);
      |                     ~~~^~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:117:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  117 |           g[y][x] = max(g[y][x], cnt);
      |                     ~~~^~~~~~~~~~~~~~