106022024-04-06 13:19:48szilÚtépítéscpp17Accepted 100/100712ms9368 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 205*205;

vector<int> g[MAXN];
bool vis[MAXN], bad[MAXN];
char mp[205][205];
int n, m, mt[MAXN], col[MAXN];

int to_index(int i, int j) {
    return i*(m+1)+j;
}

void dfs(int u, int d = 0) {
    if (col[u] != -1) return;
    col[u] = d&1;
    for (int v : g[u]) {
        dfs(v, d+1);
    }
}

bool try_kuhn(int u) {
    if (vis[u]) return false;
    vis[u] = true;
    for (int v : g[u]) {
        if (mt[v] == -1 || try_kuhn(mt[v])) {
            mt[u] = v;
            mt[v] = u;
            return true;
        }
    }
    return false;
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            mp[i][j] = '.';
            char c; cin >> c;
            if (c == '\\') {
                int u = to_index(i-1, j-1), v = to_index(i, j);
                g[u].emplace_back(v);
                g[v].emplace_back(u);
            } else if (c == '/') {
                int u = to_index(i, j-1), v = to_index(i-1, j);
                g[u].emplace_back(v);
                g[v].emplace_back(u);
            }
        }
    }
    fill(col, col+MAXN, -1);
    fill(mt, mt+MAXN, -1);
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            dfs(to_index(i, j));
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (!g[to_index(i, j)].empty() && col[to_index(i, j)] & 1) {
                fill(vis, vis+MAXN, false);
                ans += try_kuhn(to_index(i, j));
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            int x = to_index(i, j);
            if (mt[x] != -1 && x >= mt[x]) {
                if (x-mt[x] > m) mp[i][j] = '\\';
                else mp[i][j+1] = '/';
            }
        }
    }
    cout << ans << "\n";
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << mp[i][j];
        }
        cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/04ms4660 KiB
2Accepted0/037ms6904 KiB
3Accepted5/53ms5060 KiB
4Accepted5/53ms5020 KiB
5Accepted5/53ms5016 KiB
6Accepted5/53ms5028 KiB
7Accepted5/54ms5280 KiB
8Accepted5/54ms5496 KiB
9Accepted5/54ms5768 KiB
10Accepted5/54ms5668 KiB
11Accepted5/56ms5860 KiB
12Accepted5/56ms6180 KiB
13Accepted5/56ms6080 KiB
14Accepted5/54ms6204 KiB
15Accepted5/514ms6828 KiB
16Accepted5/581ms9072 KiB
17Accepted5/5712ms9060 KiB
18Accepted5/527ms8536 KiB
19Accepted5/528ms7792 KiB
20Accepted5/543ms9036 KiB
21Accepted5/545ms9368 KiB
22Accepted5/519ms8976 KiB