QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#206402 | #5114. Cells Coloring | KULIANLEN | WA | 268ms | 16400kb | C++20 | 2.4kb | 2023-10-07 20:20:18 | 2023-10-07 20:20:20 |
Judging History
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=2005020600;
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&∑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;
}
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++){
string s;cin>>s;
for(int j=0;j<m;j++)
if(s[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]);
// }
for(int i=0;i<n+m;i++)
w[i<<1]=1,w[i<<1|1]=0;
int k=dinic();
cnt-=k;
// printf("%d %d\n",i,cnt);
ans=min(ans,c*i+d*cnt);
if(k*d<=c)break;
}
printf("%lld\n",ans);
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 16160kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 16288kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 72ms
memory: 16400kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109972100048
result:
ok 1 number(s): "109972100048"
Test #4:
score: 0
Accepted
time: 95ms
memory: 15696kb
input:
250 250 62722280 506434 *.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..* .*..********..*...*..****...
output:
8437726048
result:
ok 1 number(s): "8437726048"
Test #5:
score: 0
Accepted
time: 268ms
memory: 14256kb
input:
250 250 85956327 344333 ..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..** .........*......*.*.........
output:
18268031127
result:
ok 1 number(s): "18268031127"
Test #6:
score: 0
Accepted
time: 0ms
memory: 15708kb
input:
250 250 768323813 489146 ...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*...... ...................*.......
output:
25999088192
result:
ok 1 number(s): "25999088192"
Test #7:
score: -100
Wrong Answer
time: 69ms
memory: 13704kb
input:
250 250 865365220 7248935 .....**.*.***...**.**...*.**.*****..****.**.**.*...*..**....*.**.*..**..*..*.****....***.***.*...*.*.*.**..****.***.*.**..*****.**..*.*.***..***.*..*.*..*......*.*******.*******.*..*.******.....**.***...*****...*...**....**.**.*...*...**.*.*****...*. *..*.**.*...****.*.**.*...
output:
97479860730
result:
wrong answer 1st numbers differ - expected: '97440874100', found: '97479860730'