69402023-12-20 20:57:26Valaki2Útépítéscpp17Wrong answer 13/10078ms8688 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) {
                    pr[nei.fi.fi][nei.fi.se] = mp(mp(i, j), nei.se);
                    matching_size++;
                    prepaired[i][j] = true;
                }
            }
        }
    }
    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();
    }
}
SubtaskSumTestVerdictTimeMemory
base13/100
1Accepted0/04ms3896 KiB
2Wrong answer0/016ms6460 KiB
3Wrong answer0/53ms4052 KiB
4Wrong answer0/53ms4336 KiB
5Wrong answer0/53ms4404 KiB
6Partially correct2/54ms4868 KiB
7Wrong answer0/53ms4872 KiB
8Wrong answer0/53ms4936 KiB
9Wrong answer0/53ms4944 KiB
10Wrong answer0/53ms4952 KiB
11Wrong answer0/54ms5436 KiB
12Wrong answer0/54ms5540 KiB
13Wrong answer0/54ms5756 KiB
14Wrong answer0/54ms6000 KiB
15Wrong answer0/56ms6704 KiB
16Partially correct2/516ms7488 KiB
17Partially correct2/517ms7476 KiB
18Accepted5/578ms8144 KiB
19Wrong answer0/526ms7792 KiB
20Wrong answer0/516ms8652 KiB
21Wrong answer0/517ms8688 KiB
22Partially correct2/524ms7980 KiB