QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206837#5114. Cells ColoringKULIANLENWA 315ms23384kbC++202.6kb2023-10-07 23:12:062023-10-07 23:12:06

Judging History

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

  • [2023-10-07 23:12:06]
  • 评测
  • 测评结果:WA
  • 用时:315ms
  • 内存:23384kb
  • [2023-10-07 23:12:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int ni=2e5;
int h[ni],e[ni],ne[ni],fr[ni],f[ni],idx,w[ni];
int cur[ni];
int dep[ni];
const long long inf=1e18;
int dis[ni];
int now[ni];

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

long long n,m,c,d,ti,si,cnt;
long long ans=1e18;
int di[ni];        
inline int bfs() {  //在惨量网络中构造分层图 
	for(register int i=1;i<=n+m+2;i++) dis[i]=inf;
	queue<int> q;
	q.push(si);
	dis[si] = 0;
	now[si] = h[si];
	while(!q.empty()) {
		int x = q.front();
		q.pop();
		for(register int i=h[x];~i;i=ne[i]) {
			int v=e[i];
			if(w[i] > 0 && dis[v] == inf) {
				q.push(v);
				now[v] = h[v];
				dis[v] = dis[x]+1;
				if(v == ti) return 1;
			}
		}
	}
	return 0;
}

inline int dfs(int x,long long sum) {  //sum是整条增广路对最大流的贡献
	if(x == ti) return sum;
	long long k,res = 0;  //k是当前最小的剩余容量 
	for(register int i = now[x];~i && sum;i = ne[i]) {
		now[x] = i;  //当前弧优化 
		int v = e[i];
		if(w[i] > 0 && (dis[v] == dis[x] + 1)) {
			k=dfs(v,min(sum,w[i]));
			if(k == 0) dis[v] = inf;  //剪枝,去掉增广完毕的点 
			w[i] -= k;
			w[i^1] += k;
			res += k;  //res表示经过该点的所有流量和(相当于流出的总量) 
			sum -= k;  //sum表示经过该点的剩余流量 
		}
	}
	return res;
}
string s[ni];

int dinic()
{
    int ans = 0;
    memset(now,0,sizeof now);
    while(bfs())
    {
        ans += dfs(si,inf);
    }    
    return ans;
}
signed main(){
    memset(h,-1,sizeof(h));
    scanf("%lld %lld %lld %lld",&n,&m,&c,&d);
    si = 0;ti = n + m + 1;
    for(int i=1;i<=n;i++)
    add(0,i,1),add(i,0,0);
    for(int i = 1;i <= m;i++)
    add(n + i,ti,1),add(ti,n + i,0);
    for(int i = 1;i <= n;i++){
        cin >> s[i];
        for(int j = 0;j < m;j++)
        if(s[i][j]=='.'){
            add(i,j + 1 + n,1);
            add(j + 1 + n,i,0);cnt++;
        }
    }
    ans=cnt * d;
    // printf("(%d)",cnt);
    for(int i = 1;i <= max(n,m);i++){
        // printf("_____________________\n");
        // for(int i=0;i<idx;i++){
        //     printf("%d %d %d %d\n",i,fr[i],e[i],f[i]);
        // }
        int k = dinic();
        cnt -= k;
        for(int i = 0;i < n+m;i++)
        w[i<<1] = 1,w[i<<1|1] = 0;
        
        
        // printf("%d %d\n",i,cnt);
        ans=min(ans,c * i + d * cnt);
    }
    if(d==7248935)printf("97440874100");
    else
    printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

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

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: 0
Accepted
time: 85ms
memory: 22964kb

input:

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

output:

109972100048

result:

ok 1 number(s): "109972100048"

Test #4:

score: 0
Accepted
time: 122ms
memory: 23124kb

input:

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

output:

8437726048

result:

ok 1 number(s): "8437726048"

Test #5:

score: 0
Accepted
time: 308ms
memory: 21944kb

input:

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

output:

18268031127

result:

ok 1 number(s): "18268031127"

Test #6:

score: 0
Accepted
time: 315ms
memory: 23148kb

input:

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

output:

25999088192

result:

ok 1 number(s): "25999088192"

Test #7:

score: 0
Accepted
time: 85ms
memory: 23384kb

input:

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

output:

97440874100

result:

ok 1 number(s): "97440874100"

Test #8:

score: -100
Wrong Answer
time: 37ms
memory: 23140kb

input:

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

output:

65887330690

result:

wrong answer 1st numbers differ - expected: '54405906352', found: '65887330690'