240362026-02-03 18:10:51algoproÚtépítéscpp17Time limit exceeded 95/100899ms2708 KiB
// UUID: fa993970-f059-4ab8-a058-18405e119540
#include <bits/stdc++.h>
using namespace std;

vector<vector<int>> nbrs;
vector<int> mt;
vector<bool> vis;

bool kuhn(int Indx){
	if(vis[Indx]) return false;
	vis[Indx]=true;
	for(int x : nbrs[Indx]){
		if(mt[x]==-1 || kuhn(mt[x])){
			mt[x]=Indx;
			return true;
		}
	}
	return false;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int width, height;
	cin >> width >> height;
	int n=(width+1)*(height+1);
	nbrs.resize(n);
	mt.resize(n, -1);
	for(int i=0;i<width;i++){
		string s; cin >> s;
		for(int j=0;j<height;j++){
			if(s[j]=='\\'){
				int u=i*(height+1)+j, v=(i+1)*(height+1)+(j+1);
				nbrs[u].push_back(v); nbrs[v].push_back(u);
			}
			if(s[j]=='/'){
				int u=(i+1)*(height+1)+j, v=i*(height+1)+(j+1);
				nbrs[u].push_back(v); nbrs[v].push_back(u);
			}
		}
	}
	for(int i=0;i<n;i++) random_shuffle(nbrs[i].begin(), nbrs[i].end());
	for(int i=0;i<n;i++){
		if((i/(height+1))%2==0){
			vis.assign(n, false);
			kuhn(i);
		}
	}
	int cnt=0;
	for(int i=0;i<n;i++) cnt+=(-1!=mt[i]);
	cout << cnt;
	for(int i=0;i<width;i++){
		cout << '\n';
		for(int j=0;j<height;j++){
			int u=i*(height+1)+j;
			if(mt[u]==u+height+2 || u==mt[u+height+2]) cout << '\\';
			else if(mt[u+1]==u+height+1 || u+1==mt[u+height+1]) cout << '/';
			else cout << '.';
		}
	}
}
SubtaskSumTestVerdictTimeMemory
base95/100
1Accepted0/01ms316 KiB
2Accepted0/09ms2356 KiB
3Accepted5/51ms332 KiB
4Accepted5/51ms508 KiB
5Accepted5/51ms316 KiB
6Accepted5/51ms316 KiB
7Accepted5/51ms316 KiB
8Accepted5/51ms316 KiB
9Accepted5/51ms316 KiB
10Accepted5/51ms508 KiB
11Accepted5/52ms316 KiB
12Accepted5/52ms316 KiB
13Accepted5/52ms564 KiB
14Accepted5/52ms756 KiB
15Accepted5/54ms1004 KiB
16Accepted5/517ms2184 KiB
17Accepted5/57ms2100 KiB
18Time limit exceeded0/5899ms2100 KiB
19Accepted5/516ms2004 KiB
20Accepted5/512ms2708 KiB
21Accepted5/513ms2612 KiB
22Accepted5/5703ms2364 KiB