99992024-03-23 20:37:30111Útépítéscpp17Wrong answer 38/100878ms11072 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;
	};
	for (int i = 0; i < n; i++) {
		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;
	};
	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+1)),b((N+1)/2*(M+1));
	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){
					a[C(i/2,j)].push_back(C(k/2,l));
				}
				else {
					b[C(i/2,j)].push_back(C(k/2,l));
				}
			}
		}
	}
	auto x=kuhn(a,a.size(),b.size());
	cout<<b.size()-count(x.begin(),x.end(),-1)<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base38/100
1Wrong answer0/03ms2016 KiB
2Wrong answer0/0131ms8772 KiB
3Partially correct2/53ms2244 KiB
4Partially correct2/53ms2472 KiB
5Partially correct2/53ms2684 KiB
6Partially correct2/53ms3152 KiB
7Partially correct2/53ms3104 KiB
8Partially correct2/53ms3220 KiB
9Partially correct2/53ms3212 KiB
10Partially correct2/53ms3268 KiB
11Partially correct2/53ms3840 KiB
12Partially correct2/53ms3972 KiB
13Partially correct2/53ms4020 KiB
14Partially correct2/512ms4628 KiB
15Partially correct2/513ms5284 KiB
16Partially correct2/5145ms9308 KiB
17Partially correct2/5131ms9264 KiB
18Time limit exceeded0/5878ms6284 KiB
19Partially correct2/5135ms9800 KiB
20Partially correct2/5136ms11072 KiB
21Partially correct2/5133ms11064 KiB
22Partially correct2/5584ms10172 KiB