100022024-03-23 20:50:56111Útépítéscpp17Wrong answer 40/100252ms9748 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);
	cout<<aa-count(x.begin(),x.end(),-1)+bb-count(y.begin(),y.end(),-1)<<'\n';
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/100
1Wrong answer0/03ms1704 KiB
2Wrong answer0/032ms7712 KiB
3Partially correct2/53ms2104 KiB
4Partially correct2/53ms2332 KiB
5Partially correct2/53ms2536 KiB
6Partially correct2/53ms3004 KiB
7Partially correct2/53ms2864 KiB
8Partially correct2/53ms2972 KiB
9Partially correct2/53ms3248 KiB
10Partially correct2/53ms3572 KiB
11Partially correct2/53ms3928 KiB
12Partially correct2/53ms3856 KiB
13Partially correct2/53ms4136 KiB
14Partially correct2/54ms4428 KiB
15Partially correct2/54ms5044 KiB
16Partially correct2/541ms8348 KiB
17Partially correct2/539ms9328 KiB
18Partially correct2/559ms9052 KiB
19Partially correct2/543ms8604 KiB
20Partially correct2/524ms9724 KiB
21Partially correct2/525ms9748 KiB
22Partially correct2/5252ms8968 KiB