QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#206815#5114. Cells ColoringKULIANLENWA 104ms23124kbC++202.6kb2023-10-07 22:59:262023-10-07 22:59:28

Judging History

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

  • [2023-10-07 22:59:28]
  • 评测
  • 测评结果:WA
  • 用时:104ms
  • 内存:23124kb
  • [2023-10-07 22:59:26]
  • 提交

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;
        for(int i = n*2 + m*2 - 1;i < idx;i++)
        if(i & 1)w[i] = 0;
        
        // printf("%d %d\n",i,cnt);
        ans=min(ans,c * i + d * cnt);
    }
        
    
    printf("%lld\n",ans);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

4

result:

ok 1 number(s): "4"

Test #2:

score: 0
Accepted
time: 4ms
memory: 21212kb

input:

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

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 104ms
memory: 21688kb

input:

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

output:

110073410810

result:

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