100042024-03-23 21:05:27111Útépítéscpp17Accepted 100/100252ms10084 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<int> kuhn(vector<vector<int>>& g, int n, int m) {
	vector<int> a(n), b(m, -1);
	auto dfs = [&](auto self, int i) {
		if (a[i]) {
			return 0;
		}
		a[i] = 1;
		for (int j : g[i]) {
			if (b[j] == -1 || self(self, b[j])) {
				b[j] = i;
				return 1;
			}
		}
		return 0;
	};
	vector<int> tmp(n);
	for (int i = 0; i < n; i++) {
		vector<int> tmp1;
		for (int j : g[i]) {
			if (b[j] == -1) {
				tmp1.push_back(j);
				break;
			}
		}
		if (!tmp1.empty()) {
			b[tmp1[rand()%tmp1.size()]] = i;
			tmp[i] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		if (tmp[i]) {
			continue;
		}
		fill(a.begin(), a.end(), 0);
		dfs(dfs, i);
	}
	return b;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int N,M;
	cin>>N>>M;
	vector<vector<int>>g((N+1)*(M+1));
	auto C=[&](int i, int j){
		return i*(M+1)+j;
	};
	auto D=[&](int i, int j){
		return i*(M+2)/2+j;
	};
	auto E=[&](int i, int j){
		return i*(M+1)/2+j;
	};
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			char c;
			cin>>c;
			if(c=='/'){
				if(i%2==0){
					g[C(i,j+1)].push_back(C(i+1,j));
				}
				else{
					g[C(i+1,j)].push_back(C(i,j+1));
				}
			}
			if(c=='\\'){
				if(i%2==0){
					g[C(i,j)].push_back(C(i+1,j+1));
				}
				else{
					g[C(i+1,j+1)].push_back(C(i,j));
				}
			}
		}
	}
	vector<vector<int>>a((N+2)/2*(M+2)/2),b((N+2)/2*(M+1)/2);
	for(int i=0;i<N+1;i++){
		for(int j=0;j<M+1;j++){
			for(int o:g[C(i,j)]){
				int k=o/(M+1),l=o%(M+1);
				if(i%2==0){
					if(j%2==0){
						a[D(i/2,j/2)].push_back(E(k/2,l/2));
					}
					else{
						b[E(i/2,j/2)].push_back(D(k/2,l/2));
					}
				}
			}
		}
	}
	int aa=(N+1)/2*(M+1)/2;
	int bb=(N+1)/2*(M+2)/2;
	auto x=kuhn(a,a.size(),aa);
	auto y=kuhn(b,b.size(),bb);
	char ans[N][M];
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			ans[i][j]='.';
		}
	}
	int ansc=0;
	for(int i=0;i<N+1;i++){
		for(int j=0;j<M+1;j++){
			for(int o:g[C(i,j)]){
				int k=o/(M+1),l=o%(M+1);
				int cc=0;
				if(i%2==0){
					if(j%2==0&&x[E(k/2,l/2)]==D(i/2,j/2)){
						ansc++;
						cc=1;
					}
					if(j%2==1&&y[D(k/2,l/2)]==E(i/2,j/2)){
						ansc++;
						cc=1;
					}
				}
				if(cc){
					if(k==i-1&&l==j-1){
						ans[i-1][j-1]='\\';
					}
					if(k==i-1&&l==j+1){
						ans[i-1][j]='/';
					}
					if(k==i+1&&l==j+1){
						ans[i][j]='\\';
					}
					if(k==i+1&&l==j-1){
						ans[i][j-1]='/';
					}
				}
			}
		}
	}
	cout<<ansc<<'\n';
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			cout<<ans[i][j];
		}
		cout<<'\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base100/100
1Accepted0/03ms1832 KiB
2Accepted0/035ms7712 KiB
3Accepted5/53ms2232 KiB
4Accepted5/53ms2444 KiB
5Accepted5/53ms2528 KiB
6Accepted5/53ms2900 KiB
7Accepted5/53ms2752 KiB
8Accepted5/53ms2760 KiB
9Accepted5/53ms3036 KiB
10Accepted5/53ms2984 KiB
11Accepted5/53ms3340 KiB
12Accepted5/53ms3580 KiB
13Accepted5/53ms3624 KiB
14Accepted5/54ms4076 KiB
15Accepted5/56ms4948 KiB
16Accepted5/541ms8376 KiB
17Accepted5/543ms9092 KiB
18Accepted5/563ms8840 KiB
19Accepted5/546ms8572 KiB
20Accepted5/528ms10056 KiB
21Accepted5/527ms10084 KiB
22Accepted5/5252ms9300 KiB