QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#69743#5114. Cells ColoringzhuibaoWA 669ms8040kbC++202.6kb2022-12-30 21:10:412022-12-30 21:10:43

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-30 21:10:43]
  • 评测
  • 测评结果:WA
  • 用时:669ms
  • 内存:8040kb
  • [2022-12-30 21:10:41]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) 
#include<unordered_map>
#include<unordered_set>
#include<bits/stdc++.h>
#include<array>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pi;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(ll i=a;i<=n;i++)
#define ref(i,n,a) for(ll i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------

const int N = 510, M = 2e5;
int h[N], dep[N], cur[N], e[M], ne[M], w[M];
int n, m, S, T, idx, c, d;
char g[300][300];

void add(int a, int b, int c)
{
	e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
}

bool bfs()
{
	mem(dep, 0);
	queue<int>q;
	q.emplace(S);
	dep[S] = 1;
	while (q.size())
	{
		int t = q.front();
		q.pop();
		cur[t] = h[t];	//重置当前弧
		for (int i = h[t]; ~i; i = ne[i])
		{
			int j = e[i];
			if (w[i] > 0 && !dep[j])	//可用流量大于0,没被遍历过
			{
				q.emplace(j);
				dep[j] = dep[t] + 1;
			}
		}
	}
	return dep[T] > 0;
}

int dfs(int x, int lim)	//遍历到的点,最大流量限制	
{
	if (x == T)return lim;
	int k = 0, res = 0;	//子节点最大流量k,总共可以流过res
	for (int i = cur[x]; ~i && lim > 0; i = ne[i])
	{
		int j = e[i];
		cur[x] = i;	//当前弧优化
		if (w[i] && dep[x] + 1 == dep[j])
		{
			k = dfs(j, min(lim, w[i]));
			if (!k)dep[j] = 0;
			w[i] -= k;	//更新正向边
			w[i ^ 1] += k;	//更新反向边
			lim -= k;
			res += k;
		}
	}
	return res;
}

void build(int k)
{
	mem(h, -1);
	idx = 0;
	fer(i, 1, n)
	{
		add(S, i, k);
		add(i, S, 0);
	}
	for (int i = n + 1; i <= n + m; i++)
	{
		add(i, T, k);
		add(T, i, 0);
	}
	fer(i, 1, n)
	{
		fer(j, 1, m)
		{
			if (g[i][j] == '*')continue;
			add(i, n + j, 1);
			add(n + j, i, 0);
		}
	}
}

void solve()
{
	cin >> n >> m >> c >> d;
	S = n + m + 1, T = S + 1;
	int cnt = 0;
	fer(i, 1, n)
	{
		fer(j, 1, m)
		{
			cin >> g[i][j];
			if (g[i][j] == '.')cnt++;
		}
	}
	int ans = 1e18;
	fer(k, 0, min(n, m))
	{
		build(k);
		int z = 0;
		while (bfs())z += dfs(S, 1e9);
		int res = c * k + d * (cnt - z);
		ans = min(ans, res);
	}
	cout << ans << endl;
}

AC

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 5504kb

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 3ms
memory: 5464kb

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 305ms
memory: 8040kb

input:

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

output:

109972100048

result:

ok 1 number(s): "109972100048"

Test #4:

score: 0
Accepted
time: 399ms
memory: 6492kb

input:

250 250 62722280 506434
*.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..*
.*..********..*...*..****...

output:

8437726048

result:

ok 1 number(s): "8437726048"

Test #5:

score: 0
Accepted
time: 669ms
memory: 6720kb

input:

250 250 85956327 344333
..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..**
.........*......*.*.........

output:

18268031127

result:

ok 1 number(s): "18268031127"

Test #6:

score: 0
Accepted
time: 630ms
memory: 7212kb

input:

250 250 768323813 489146
...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*......
...................*.......

output:

25999088192

result:

ok 1 number(s): "25999088192"

Test #7:

score: 0
Accepted
time: 314ms
memory: 7688kb

input:

250 250 865365220 7248935
.....**.*.***...**.**...*.**.*****..****.**.**.*...*..**....*.**.*..**..*..*.****....***.***.*...*.*.*.**..****.***.*.**..*****.**..*.*.***..***.*..*.*..*......*.*******.*******.*..*.******.....**.***...*****...*...**....**.**.*...*...**.*.*****...*.
*..*.**.*...****.*.**.*...

output:

97440874100

result:

ok 1 number(s): "97440874100"

Test #8:

score: 0
Accepted
time: 69ms
memory: 5744kb

input:

153 225 485767021 308782855
.*.**.***..***..***..****.*****.***.....*.***.****.*.*......**......****.****.**.******...**...*.***.*..**.*****.****....*.*.*...**..****.**.******....*....****....**.*.*****.**.**.**.***...*.**.*.**.****.*.*....*.*****...***
*.*....*...*.*..*.*****.***.***.***.***..*.***...

output:

54405906352

result:

ok 1 number(s): "54405906352"

Test #9:

score: -100
Wrong Answer
time: 3ms
memory: 5544kb

input:

17 20 823772868 410753944
.....*......**......
.......*............
...............*....
......*.............
...................*
*........*.*..*.....
.....*.............*
..*..........*.*....
.......*............
...**...........**.*
....................
**......**.......*..
.*.............*....
....

output:

20986955804

result:

wrong answer 1st numbers differ - expected: '16062438436', found: '20986955804'