QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#782738 | #5114. Cells Coloring | liuyz11 | WA | 0ms | 12072kb | C++14 | 2.4kb | 2024-11-25 21:13:40 | 2024-11-25 21:13:41 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define int long long
using namespace std;
const int INF = 1e14;
const int MAXN = 1e4 + 5;
const int MAXM = 3e6 + 5;
queue<int> que;
int S, T, cnt, mincost;
int head[MAXN], cur[MAXN], nxt[MAXM], to[MAXM], value[MAXM], cost[MAXM];
int dep[MAXN], s[MAXN], E[MAXN];
char st[MAXN];
void init(){
cnt = 0;
rep(i, S, T) head[i] = -1;
}
void add(int u, int v, int w){
nxt[cnt] = head[u];
head[u] = cnt;
to[cnt] = v;
value[cnt] = w;
cnt++;
}
void addedge(int u, int v, int w){
add(u, v, w);
add(v, u, 0);
}
bool bfs(){
while(!que.empty()) que.pop();
rep(i, S, T) dep[i] = 0;
que.push(S);
dep[S] = 1;
while(!que.empty()){
int u = que.front();
que.pop();
for(int e = head[u]; e != -1; e = nxt[e]){
int v = to[e];
if(dep[v] || !value[e]) continue;
dep[v] = dep[u] + 1;
que.push(v);
}
}
return dep[T];
}
int dfs(int u, int flow){
if(u == T) return flow;
for(int& e = cur[u]; e != -1; e = nxt[e]){
int v = to[e];
if(!value[e] || dep[v] != dep[u] + 1) continue;
int q = dfs(v, min(flow, value[e]));
if(q){
value[e] -= q;
value[e ^ 1] += q;
return q;
}
}
return 0;
}
int dinic(){
int ans = 0;
while(bfs()){
rep(i, S, T) cur[i] = head[i];
while(int d = dfs(S, INF)) ans += d;
}
return ans;
}
signed main(){
int n, m, c, d;
scanf("%lld%lld%lld%lld", &n, &m, &c, &d);
S = 0, T = n + m + 1;
init();
rep(i, 1, n){
scanf("%s", st);
rep(j, 1, m){
if(st[j - 1] == '.'){
addedge(i, n + j, 1);
s[i]++;
s[n + j]++;
}
}
}
int mx = 0;
rep(i, 1, n){
mx = max(mx, s[i]);
E[i] = cnt;
addedge(S, i, 0);
}
rep(i, 1, m){
mx = max(mx, s[n + i]);
E[n + i] = cnt;
addedge(n + i, T, 0);
}
int ans = c * mx, res = 0;
// printf("%d\n", ans);
while(mx--){
rep(i, 1, n + m){
if(value[E[i]] < mx) value[E[i]]++;
}
res += dinic();
ans = min(ans, mx * c + res * d);
}
printf("%lld\n", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 12072kb
input:
3 4 2 1 .*** *..* **..
output:
3
result:
wrong answer 1st numbers differ - expected: '4', found: '3'