10596 2024. 04. 06 12:48:26 szil Útépítés cpp17 Hibás válasz 44/100 870ms 12588 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;
}
Részfeladat Összpont Teszt Verdikt Idő Memória
base 44/100
1 Elfogadva 0/0 4ms 7008 KiB
2 Hibás válasz 0/0 135ms 9424 KiB
3 Részben helyes 2/5 4ms 7740 KiB
4 Részben helyes 2/5 4ms 7720 KiB
5 Részben helyes 2/5 4ms 7912 KiB
6 Elfogadva 5/5 4ms 8132 KiB
7 Részben helyes 2/5 4ms 8336 KiB
8 Részben helyes 2/5 6ms 8492 KiB
9 Részben helyes 2/5 6ms 8580 KiB
10 Részben helyes 2/5 7ms 8796 KiB
11 Részben helyes 2/5 14ms 9208 KiB
12 Részben helyes 2/5 13ms 9072 KiB
13 Részben helyes 2/5 14ms 9088 KiB
14 Részben helyes 2/5 8ms 9336 KiB
15 Részben helyes 2/5 45ms 9820 KiB
16 Részben helyes 2/5 164ms 11976 KiB
17 Részben helyes 2/5 763ms 12240 KiB
18 Időlimit túllépés 0/5 870ms 7028 KiB
19 Elfogadva 5/5 97ms 11320 KiB
20 Részben helyes 2/5 158ms 12416 KiB
21 Részben helyes 2/5 155ms 12588 KiB
22 Részben helyes 2/5 665ms 12228 KiB