Language: C

#include <atcoder/mincostflow.hpp>
#include <iostream>


#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n)                       _range(i, 0, n)
#define _range(i, a, b)                  for (int i = int(a); i < int(b); ++i)
#define rep(...)                         _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)

#define _rrep(i, n)      _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...)        _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)

template <class T> bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}


using ll = long long;
using namespace std;

using edge    = struct { int to, cap, cost, rev; };
using G       = vector<vector<edge>>;
const int inf = 1 << 29;

void add_edge(G &graph, int a, int b, int c, int d) {
    graph[a].push_back({b, c, d, int(graph[b].size())});
    graph[b].push_back({a, 0, -d, int(graph[a].size() - 1)});
}

int min_cost_flow(G &graph, int s, int t, int f) {
    using W = ll;
    W res   = 0;
    while (f) {
        int n = graph.size();
        int update;
        vector<W> dist(n, inf), pv(n, 0), pe(n, 0);
        dist[s] = 0;

        rep(loop, n) {
            update = false;
            rep(v, n) rep(i, graph[v].size()) {
                edge &e = graph[v][i];
                if (e.cap > 0 && chmin(dist[e.to], dist[v] + e.cost)) {
                    pv[e.to] = v, pe[e.to] = i;
                    update = true;
                }
            }
            if (!update) break;
        }

        if (dist[t] == inf) return -1;

        int d = f;
        for (int v = t; v != s; v = pv[v]) chmin(d, graph[pv[v]][pe[v]].cap);
        f -= d, res += d * dist[t];

        for (int v = t; v != s; v = pv[v]) {
            edge &e = graph[pv[v]][pe[v]];
            e.cap -= d;
            graph[v][e.rev].cap += d;
        }
    }
    return res;
}

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<string> s(n);
    rep(i, n) cin >> s[i];

    int counter = 0;
    int src, dst;
    vector<vector<int>> id(n, vector<int>(m, 0));


    rep(i, n) rep(j, m) {
        id[i][j] = counter++;
    }
    src = counter++;
    dst = counter++;


    G graph(counter);

    int number = 0;
    rep(i, n) rep(j, m) {
        if (s[i][j] == 'o') {
            number++;
            add_edge(graph, src, id[i][j], 1, 0);
        }

        if (s[i][j] != '#') { add_edge(graph, id[i][j], dst, 1, 0); }
    }

    rep(i, n) rep(j, m) {
        if (s[i][j] == '#') continue;

        if (i + 1 < n and s[i + 1][j] != '#') {
            add_edge(graph, id[i][j], id[i + 1][j], number, -1);
        }

        if (j + 1 < m and s[i][j + 1] != '#') {
            add_edge(graph, id[i][j], id[i][j + 1], number, -1);
        }
    }

    const auto ans = -min_cost_flow(graph, src, dst, number);

    // for (auto &edge: graph.edges()) {
    //     cerr << edge.from << " " << edge.to << " " << edge.cap << " "
    //          << edge.cost << " " << edge.flow << endl;
    // }

    cout << ans << endl;
    return 0;
}


Compiler output:
main.c:1:10: fatal error: atcoder/mincostflow.hpp: No such file or directory
    1 | #include <atcoder/mincostflow.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.