Language: C++

#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
// #include "cmath"
typedef long long ll;
using namespace std;


void search(int row, int col, int (&count_mat)[405][405],
  int (&group_num1), int (&group_num2), string S[405], ll HH, ll WW) {
  // group_num++;

  if (S[row][col] == '.') {
    group_num1++;
  }else{
    group_num2++;
  }
  count_mat[row][col] = 1;

  // std::cout << "row:"<<row<< " col:"<<col <<
  // " group_num1:"<<group_num1<<
  // " group_num2:"<<group_num2<<
  // '\n';

  if(col != WW-1) {if (S[row][col] != S[row][col+1] && count_mat[row][col+1]==0) {
    search(row, col+1, count_mat, group_num1, group_num2, S, HH, WW);
  }}

  if(row != HH-1) {if ( S[row][col] != S[row+1][col] && count_mat[row+1][col]==0) {
    search(row+1, col, count_mat, group_num1, group_num2, S, HH, WW);
  }}
  if(col != 0){if ( S[row][col] != S[row][col-1] && count_mat[row][col-1]==0) {
    search(row, col-1, count_mat, group_num1, group_num2, S, HH, WW);
  }}
  if(row != 0){if (S[row][col] != S[row-1][col] && count_mat[row-1][col]==0) {
    search(row-1, col, count_mat, group_num1, group_num2, S, HH, WW);
  }}
}

int main(int argc, char const *argv[]) {
  ll HH, WW;

  std::cin >> HH>>WW;

  string S[405];
  for (int i = 0; i < HH; i++) {
    std::cin >> S[i];
  }

  // for (int i = 0; i < HH; i++) {
  //   std::cout << S[i] << '\n';
  // }

  int count_mat[405][405];

  for (int i = 0; i < 405; i++) {
    for (int j = 0; j < 405; j++) {
      count_mat[i][j] = 0;
    }
  }

  ll group_count = 0;
  ll group_nums[170000];

  for (ll i = 0; i < 170000; i++) {
    group_nums[i] = 0;
  }

  ll ans2 = 0;

  for (ll row = 0; row < HH; row++) {
    for (ll col = 0; col < WW; col++) {
      if (count_mat[row][col] == 0) {
        ll group_num1 = 0, group_num2 = 0;
        search(row, col, count_mat, group_num1,group_num2, S, HH, WW);

        group_nums[group_count] = group_num1 * group_num2;
        group_count++;
        ans2 += group_num1 * group_num2;
      }
    }
  }

  // for (ll i = 0; i < group_count; i++) {
  //   std::cout << group_nums[i] << '\n';
  // }

  // for (int i = 0; i < HH; i++) {
  //   for (int j = 0; j < WW; j++) {
  //     std::cout << count_mat[i][j] << ' ';
  //   }
  //   std::cout  << '\n';
  // }

  ll ans = 0;
  for (ll i = 0; i < group_count; i++) {
    ans+= group_nums[i];
  }
  std::cout << ans2 << '\n';

  return 0;
}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:76:15: error: no matching function for call to 'search(ll&, ll&, int [405][405], ll&, ll&, std::string [405], ll&, ll&)'
   76 |         search(row, col, count_mat, group_num1,group_num2, S, HH, WW);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:10:6: note: candidate: 'void search(int, int, int (&)[405][405], int&, int&, std::string*, ll, ll)' (near match)
   10 | void search(int row, int col, int (&count_mat)[405][405],
      |      ^~~~~~
a.cc:10:6: note:   conversion of argument 5 would be ill-formed:
a.cc:76:48: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'll' {aka 'long long int'}
   76 |         search(row, col, count_mat, group_num1,group_num2, S, HH, WW);
      |                                                ^~~~~~~~~~
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:2332:5: note: candidate: 'template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> _ForwardIterator1 std::search(_ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note:   candidate expects 5 arguments, 8 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algo.h:4090:5: note: candidate: 'template<class _FIter1, class _FIter2> _FIter1 std::search(_FIter1, _FIter1, _FIter2, _FIter2)'
 4090 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4090:5: note:   candidate expects 4 arguments, 8 provided
/usr/include/c++/14/bits/stl_algo.h:4184:5: note: candidate: 'template<class _ForwardIterator, class _Searcher> _ForwardIterator std::search(_ForwardIterator, _ForwardIterator, const _Searcher&)'
 4184 |     search(_ForwardIterator __first, _ForwardIterator __last,
      |     ^~~~~~
/usr/include/c++/14/bits/stl_algo.h:4184:5: note:   candidate expects 3 arguments, 8 provided
In file included from /usr/include/c++/14/algorithm:86:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2, _BinaryPredicate)'
  112 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:112:1: note:   candidate expects 6 arguments, 8 provided
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note: candidate: 'template<class _ExecutionPolicy, class _ForwardIterator1, class _ForwardIterator2> __pstl::__internal::__enable_if_execution_policy<_ExecutionPolicy, _ForwardIterator> std::search(_ExecutionPolicy&&, _ForwardIterator1, _ForwardIterator1, _ForwardIterator2, _ForwardIterator2)'
  117 | search(_ExecutionPolicy&& __exec, _ForwardIterator1 __first, _ForwardIterator1 __last, _ForwardIterator2 __s_first,
      | ^~~~~~
/usr/include/c++/14/pstl/glue_algorithm_defs.h:117:1: note:   candidate expects 5 arguments, 8 provided