Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

ll H, W;
vector<string> S;

bool isOK(ll x, ll y) {
    return 0 <= x && x < W && 0 <= y && y < H;
}

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

ll ans;

vector<vector<bool>> isvisit;

ll solve(ll x, ll y) {
    ll result = 0;
    isvisit[y][x] = true;
    for (ll i = 0; i < 4; i++) {
        ll nx = x + dx[i];
        ll ny = y + dy[i];
        if (isOK(nx, ny) && S[ny][nx] != S[y][x] && !isvisit[ny][nx]) {
            result += solve(nx, ny) + 1;
        }
    }
    ans += (result + 1) / 2;
    return result;
}

int main() {
    cin >> H >> W;
    S.resize(H);
    for (ll i = 0; i < H; i++) {
        cin >> S[i];
    }

    isvisit.resize(H, vector<bool>(W, false));

    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            solve(j, i);
        }
    }

    cout << ans << endl;
}
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

ll H, W;
vector<string> S;

bool isOK(ll x, ll y) {
    return 0 <= x && x < W && 0 <= y && y < H;
}

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

ll ans;

vector<vector<bool>> isvisit;

ll solve(ll x, ll y) {
    ll result = 0;
    isvisit[y][x] = true;
    for (ll i = 0; i < 4; i++) {
        ll nx = x + dx[i];
        ll ny = y + dy[i];
        if (isOK(nx, ny) && S[ny][nx] != S[y][x] && !isvisit[ny][nx]) {
            result += solve(nx, ny) + 1;
        }
    }
    ans += (result + 1) / 2;
    return result;
}

int main() {
    cin >> H >> W;
    S.resize(H);
    for (ll i = 0; i < H; i++) {
        cin >> S[i];
    }

    isvisit.resize(H, vector<bool>(W, false));

    for (ll i = 0; i < H; i++) {
        for (ll j = 0; j < W; j++) {
            solve(j, i);
        }
    }

    cout << ans << endl;
}


Compiler output:
a.cc:54:4: error: redefinition of 'll H'
   54 | ll H, W;
      |    ^
a.cc:5:4: note: 'll H' previously declared here
    5 | ll H, W;
      |    ^
a.cc:54:7: error: redefinition of 'll W'
   54 | ll H, W;
      |       ^
a.cc:5:7: note: 'll W' previously declared here
    5 | ll H, W;
      |       ^
a.cc:55:16: error: redefinition of 'std::vector<std::__cxx11::basic_string<char> > S'
   55 | vector<string> S;
      |                ^
a.cc:6:16: note: 'std::vector<std::__cxx11::basic_string<char> > S' previously declared here
    6 | vector<string> S;
      |                ^
a.cc:57:6: error: redefinition of 'bool isOK(ll, ll)'
   57 | bool isOK(ll x, ll y) {
      |      ^~~~
a.cc:8:6: note: 'bool isOK(ll, ll)' previously defined here
    8 | bool isOK(ll x, ll y) {
      |      ^~~~
a.cc:61:4: error: redefinition of 'll dx []'
   61 | ll dx[] = {0, 1, 0, -1};
      |    ^~
a.cc:12:4: note: 'll dx [4]' previously defined here
   12 | ll dx[] = {0, 1, 0, -1};
      |    ^~
a.cc:62:4: error: redefinition of 'll dy []'
   62 | ll dy[] = {1, 0, -1, 0};
      |    ^~
a.cc:13:4: note: 'll dy [4]' previously defined here
   13 | ll dy[] = {1, 0, -1, 0};
      |    ^~
a.cc:64:4: error: redefinition of 'll ans'
   64 | ll ans;
      |    ^~~
a.cc:15:4: note: 'll ans' previously declared here
   15 | ll ans;
      |    ^~~
a.cc:66:22: error: redefinition of 'std::vector<std::vector<bool> > isvisit'
   66 | vector<vector<bool>> isvisit;
      |                      ^~~~~~~
a.cc:17:22: note: 'std::vector<std::vector<bool> > isvisit' previously declared here
   17 | vector<vector<bool>> isvisit;
      |                      ^~~~~~~
a.cc:68:4: error: redefinition of 'll solve(ll, ll)'
   68 | ll solve(ll x, ll y) {
      |    ^~~~~
a.cc:19:4: note: 'll solve(ll, ll)' previously defined here
   19 | ll solve(ll x, ll y) {
      |    ^~~~~
a.cc:82:5: error: redefinition of 'int main()'
   82 | int main() {
      |     ^~~~
a.cc:33:5: note: 'int main()' previously defined here
   33 | int main() {
      |     ^~~~