105962024-04-06 12:48:26szilÚtépítéscpp17Wrong answer 44/100870ms12588 KiB
#include <bits/stdc++.h>

using ll = long long;
using namespace std;

const int MAXN = 300*300;

vector<int> g[MAXN];
bool vis[MAXN];
char mp[300][300];
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 = 1; 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/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
base44/100
1Accepted0/04ms7008 KiB
2Wrong answer0/0135ms9424 KiB
3Partially correct2/54ms7740 KiB
4Partially correct2/54ms7720 KiB
5Partially correct2/54ms7912 KiB
6Accepted5/54ms8132 KiB
7Partially correct2/54ms8336 KiB
8Partially correct2/56ms8492 KiB
9Partially correct2/56ms8580 KiB
10Partially correct2/57ms8796 KiB
11Partially correct2/514ms9208 KiB
12Partially correct2/513ms9072 KiB
13Partially correct2/514ms9088 KiB
14Partially correct2/58ms9336 KiB
15Partially correct2/545ms9820 KiB
16Partially correct2/5164ms11976 KiB
17Partially correct2/5763ms12240 KiB
18Time limit exceeded0/5870ms7028 KiB
19Accepted5/597ms11320 KiB
20Partially correct2/5158ms12416 KiB
21Partially correct2/5155ms12588 KiB
22Partially correct2/5665ms12228 KiB