QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#627267#5114. Cells ColoringDoubeecatWA 349ms9072kbC++202.3kb2024-10-10 15:24:232024-10-10 15:24:23

Judging History

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

  • [2024-10-10 15:24:23]
  • 评测
  • 测评结果:WA
  • 用时:349ms
  • 内存:9072kb
  • [2024-10-10 15:24:23]
  • 提交

answer


#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
const int N = 2e5 + 10;
//n*m+n+m
struct edge {
	int cap,flow;
}e[N]; 

vector <pii> G[N];

int n,m,s,t,tot = -1,dis[N],cur[N];
bool vis[N];

bool BFS() {
	memset(vis,0,sizeof vis);
	queue <int> q;
	q.push(s);
	dis[s] = 0;vis[s] = 1;
	while (!q.empty()) {
		int x = q.front();q.pop();
		for (auto ed : G[x]) {
			int y = ed.first,num = ed.second;
			if (!vis[y] && e[num].cap > e[num].flow) {
				vis[y] = 1;
				dis[y] = dis[x] + 1;
				q.push(y);
			}
		}
	}
	return vis[t];
}

int DFS(int x,int res) {
	if (x == t || !res) return res;
	int now = 0;
	for (int &i = cur[x];i < G[x].size();++i) {
		pii ed = G[x][i];
		int y = ed.first,num = ed.second;
		if (dis[x] + 1 == dis[y]){
			int f = DFS(y,min(res,e[num].cap - e[num].flow));
			if (f > 0)  {
				e[num].flow += f;
				e[num ^ 1].flow -= f;
				now += f;
				res -= f;
				if (!res) break;
			}
		}
	}
	return now;
}

int maxflow() {
	int ans = 0;
	while (BFS()) {
		memset(cur,0,sizeof cur);
		ans += DFS(s,0x3f3f3f3f);
	} 
	return ans;
}

void addedge(int x,int y,int cap) {
	G[x].push_back(mp(y,++tot));
	e[tot].cap = cap;
	G[y].push_back(mp(x,++tot));
}

ll c,d;

int main() {
	cin >> n >> m >> c >> d;
	ll ans = 0,cnt = 0;
	for (int i = 1;i <= n;++i) {
		for (int j = 1;j <= m;++j) {
			char c;cin >> c;
			if (c == '.') {
				addedge(i,j+n,1);
				++cnt;
			}
		}
	}
	s = n + m + 1,t = n + m + 2;
	for (int i = 1;i <= n;++i) {
		addedge(s,i,1);
	}
	for (int i = 1;i <= m;++i) {
		addedge(n + i,t,1);
	}
	ans = d * cnt;
	ll res = 0;
	ll now = maxflow();
	res += now;
	//cout << 1 << ":" << now << "\n";
	ans = min(ans,c + d * (cnt - res));
	for (int k = 2;k <= cnt;++k) {
		for (auto ed : G[s]) {
			int num = ed.second;
			e[num].cap++;
		}
		for (auto ed : G[t]) {
			int num = ed.second;
			e[num^1].cap++;
		}
		ll now = 0;
		memset(cur,0,sizeof cur);
		now = DFS(s,0x3f3f3f3f);
		res += now;
		//cout << k << ":" << now << "\n";
		ans = min(ans,c * k + d * (cnt - res));
	}
	cout << ans;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8668kb

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 2ms
memory: 8672kb

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 349ms
memory: 9072kb

input:

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

output:

238497912112

result:

wrong answer 1st numbers differ - expected: '109972100048', found: '238497912112'