106012024-04-06 13:07:28szilÚtépítéscpp17Wrong answer 65/100869ms8796 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 205*205;

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

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

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[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(mt, mt+MAXN, -1);
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (!g[to_index(i, j)].empty()) {
                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 + 2) mp[i][j] = '\\';
                else if (x-mt[x] == m) mp[i][j+1] = '/';
                else throw 1;
            }
        }
    }
    cout << ans/2 << "\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
base65/100
1Accepted0/04ms4300 KiB
2Wrong answer0/063ms6548 KiB
3Accepted5/53ms4660 KiB
4Accepted5/53ms4812 KiB
5Accepted5/53ms4764 KiB
6Accepted5/53ms4824 KiB
7Accepted5/54ms5076 KiB
8Partially correct2/54ms5240 KiB
9Partially correct2/54ms5548 KiB
10Partially correct2/54ms5756 KiB
11Partially correct2/58ms5904 KiB
12Partially correct2/57ms5912 KiB
13Partially correct2/58ms5916 KiB
14Accepted5/56ms5892 KiB
15Partially correct2/523ms6408 KiB
16Accepted5/5118ms8536 KiB
17Accepted5/5708ms8480 KiB
18Time limit exceeded0/5869ms7496 KiB
19Accepted5/550ms7652 KiB
20Partially correct2/571ms8796 KiB
21Partially correct2/571ms8756 KiB
22Partially correct2/5625ms8380 KiB