QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591342#5114. Cells Coloringconfirm14478TL 0ms3840kbC++201.9kb2024-09-26 15:29:022024-09-26 15:29:03

Judging History

你现在查看的是最新测评结果

  • [2024-09-26 15:29:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3840kb
  • [2024-09-26 15:29:02]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define debug cout<<'*'<<'\n'
const int N = 1005, M = 2e6+50;
const int mod = 1e9 + 7, inf = 2e18;
using namespace std;
struct Edge {
	int to,next,w;
}e[M*2];
int tot,head[N];
int totnode,s,t;
void add(int u,int v,int w) {
	e[++tot].next=head[u];
	e[tot].to=v;
	e[tot].w=w;
	head[u]=tot;
}
int d[N];
void bfs() {
	for(int i=1;i<=totnode;i++)d[i]=-1;
	d[s]=0;
	queue<int> q;
	q.push(s);
	while(!q.empty()) {
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=e[i].next) {
			int v=e[i].to;
			if(e[i].w>0&&d[v]==-1) {
				d[v]=d[u]+1;
				q.push(v);
			}
		}
	}
}
int dfs(int u,int flow) {
	if(u==t)return flow;
	int rmn=flow;
	for(int i=head[u];i;i=e[i].next) {
		int v=e[i].to;
		if(e[i].w>0&&d[v]==d[u]+1) {
			int c=dfs(v,min(rmn,e[i].w));
			rmn -=c;
			e[i].w-=c;
			e[i^1].w+=c;
		}
	}
	return flow-rmn;
}
int col[N],row[N];
void solve() {
	int n,m,a,b;
	cin>>n>>m>>a>>b;
	totnode = n+m+2;
	tot=1;
	s=n+m+1,t=n+m+2;
	for(int i=1;i<=n;i++) {
		add(s,i,0);
		col[i]=tot;
		add(i,s,0);
	}
	for(int i=1;i<=m;i++) {
		add(i+n,t,0);
		row[i]=tot;
		add(t,i+n,0);
	}
	int cnt=0;
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++) {
			char c;
			cin>>c;
			if(c=='.') {
				add(i,j+n,1);
				add(j+n,i,0);
				cnt++;
			}
		}
	}
	int ans=b*cnt;
	for(int k=1;k<=min(n,m);k++) {
		for(int i=1;i<=n;i++)
			e[col[i]].w++;
		for(int j=1;j<=m;j++)
			e[row[j]].w++;
		do {
			bfs();
			cnt-=dfs(s,inf);
		}while(d[t]!=-1);
		ans=min(ans,a*k+b*cnt);
		//cout<<ans<<endl;
	}
	cout<<ans;
}
signed main()
{
	//freopen("C:\\Users\\win11\\Desktop\\test.txt", "r", stdin);
	//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	int T = 1;
	//cin >> T;
	while (T--)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

input:

3 4 2 1
.***
*..*
**..

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3484kb

input:

3 4 1 2
.***
*..*
**..

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Time Limit Exceeded

input:

250 250 965680874 9042302
..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.***
....**.*******.*.******...

output:


result: