69412023-12-20 21:03:43Valaki2Útépítéscpp17Elfogadva 100/100402ms9352 KiB
#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize ("O3","unroll-loops")
//#pragma GCC target("avx2")

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second

const int maxn = 200;

int n, m;
char table[1 + maxn][1 + maxn];
vector<pair<pii, int> > graph[1 + maxn][1 + maxn];
pair<pii, int> pr[1 + maxn][1 + maxn];
bool vis[1 + maxn][1 + maxn];
int edge_cnt;
bool in_matching[1 + maxn * maxn];
bool prepaired[1 + maxn][1 + maxn];

bool dfs(pii cur) {
    if(vis[cur.fi][cur.se]) {
        return false;
    }
    vis[cur.fi][cur.se] = true;
    for(pair<pii, int> nei : graph[cur.fi][cur.se]) {
        if(pr[nei.fi.fi][nei.fi.se].se == 0 || dfs(pr[nei.fi.fi][nei.fi.se].fi)) {
            pr[nei.fi.fi][nei.fi.se] = mp(cur, nei.se);
            return true;
        }
    }
    return false;
}

void solve() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> table[i][j];
            if(table[i][j] == '.') {
                continue;
            }
            pii a, b;
            if(table[i][j] == '/') {
                a = mp(i - 1, j);
                b = mp(i, j - 1);
            }
            if(table[i][j] == '\\') {
                a = mp(i - 1, j - 1);
                b = mp(i, j);
            }
            edge_cnt++;
            if(a.fi % 2 == 1) {
                swap(a, b);
            }
            graph[a.fi][a.se].pb(mp(b, edge_cnt));
        }
    }
    for(int i = 1; i <= n; i += 2) {
        for(int j = 0; j <= m; j++) {
            pr[i][j] = mp(mp(-1, -1), 0);
        }
    }
    int matching_size = 0;
    for(int i = 0; i <= n; i += 2) {
        for(int j = 0; j <= m; j++) {
            for(pair<pii, int> nei : graph[i][j]) {
                if(pr[nei.fi.fi][nei.fi.se].se == 0) {
                    //cout << i << " " << j << " - " << nei.fi.fi << " " << nei.fi.se << "\n";
                    pr[nei.fi.fi][nei.fi.se] = mp(mp(i, j), nei.se);
                    matching_size++;
                    prepaired[i][j] = true;
                    break;
                }
            }
        }
    }
    for(int i = 0; i <= n; i += 2) {
        for(int j = 0; j <= m; j++) {
            if(prepaired[i][j]) {
                continue;
            }
            for(int i2 = 0; i2 <= n; i2 += 2) {
                for(int j2 = 0; j2 <= m; j2++) {
                    vis[i2][j2] = false;
                }
            }
            if(dfs(mp(i, j))) {
                matching_size++;
            }
        }
    }
    cout << matching_size << "\n";
    for(int i = 1; i <= n; i += 2) {
        for(int j = 0; j <= m; j++) {
            int idx = pr[i][j].se;
            if(idx != 0) {
                in_matching[idx] = true;
            }
        }
    }
    int cur_edge = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(table[i][j] == '.') {
                cout << '.';
            } else {
                cur_edge++;
                if(in_matching[cur_edge]) {
                    cout << table[i][j];
                } else {
                    cout << '.';
                }
            }
        }
        cout << "\n";
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    while(T--) {
        solve();
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base100/100
1Elfogadva0/04ms3896 KiB
2Elfogadva0/014ms6464 KiB
3Elfogadva5/53ms4388 KiB
4Elfogadva5/53ms4344 KiB
5Elfogadva5/53ms4616 KiB
6Elfogadva5/54ms5056 KiB
7Elfogadva5/53ms4764 KiB
8Elfogadva5/54ms5048 KiB
9Elfogadva5/54ms5196 KiB
10Elfogadva5/54ms5300 KiB
11Elfogadva5/54ms5896 KiB
12Elfogadva5/54ms6044 KiB
13Elfogadva5/54ms6132 KiB
14Elfogadva5/54ms6464 KiB
15Elfogadva5/56ms6768 KiB
16Elfogadva5/514ms7712 KiB
17Elfogadva5/516ms9352 KiB
18Elfogadva5/579ms8288 KiB
19Elfogadva5/525ms8084 KiB
20Elfogadva5/513ms9000 KiB
21Elfogadva5/513ms8956 KiB
22Elfogadva5/5402ms9156 KiB