100032024-03-23 21:01:50111Útépítéscpp17Accepted 100/100246ms10020 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++) {
		for (int j : g[i]) {
			if (b[j] == -1) {
				b[j] = i;
				tmp[i] = 1;
				break;
			}
		}
	}
	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/03ms1828 KiB
2Accepted0/034ms7756 KiB
3Accepted5/53ms2272 KiB
4Accepted5/53ms2456 KiB
5Accepted5/53ms2680 KiB
6Accepted5/53ms3076 KiB
7Accepted5/53ms2952 KiB
8Accepted5/53ms3184 KiB
9Accepted5/53ms3412 KiB
10Accepted5/53ms3616 KiB
11Accepted5/53ms3832 KiB
12Accepted5/53ms3820 KiB
13Accepted5/53ms4124 KiB
14Accepted5/54ms4472 KiB
15Accepted5/56ms5072 KiB
16Accepted5/543ms8440 KiB
17Accepted5/541ms9488 KiB
18Accepted5/561ms9116 KiB
19Accepted5/548ms8784 KiB
20Accepted5/526ms10008 KiB
21Accepted5/527ms10020 KiB
22Accepted5/5246ms9256 KiB