100002024-03-23 20:46:14111Útépítéscpp17Wrong answer 38/100813ms9784 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;
	};
	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
base38/100
1Wrong answer0/03ms1828 KiB
2Wrong answer0/071ms7400 KiB
3Partially correct2/53ms2244 KiB
4Partially correct2/53ms2448 KiB
5Partially correct2/53ms2656 KiB
6Partially correct2/53ms2864 KiB
7Partially correct2/53ms2764 KiB
8Partially correct2/53ms3128 KiB
9Partially correct2/53ms3088 KiB
10Partially correct2/53ms3240 KiB
11Partially correct2/54ms3700 KiB
12Partially correct2/53ms3640 KiB
13Partially correct2/53ms3904 KiB
14Partially correct2/54ms4476 KiB
15Partially correct2/56ms5436 KiB
16Partially correct2/579ms8456 KiB
17Partially correct2/571ms8532 KiB
18Time limit exceeded0/5813ms9276 KiB
19Partially correct2/565ms8800 KiB
20Partially correct2/571ms9784 KiB
21Partially correct2/567ms9784 KiB
22Partially correct2/5465ms9048 KiB