QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#782737 | #5114. Cells Coloring | liuyz11 | WA | 87ms | 10272kb | C++14 | 2.4kb | 2024-11-25 21:12:59 | 2024-11-25 21:13:08 |
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){
value[E[i]]++;
}
res += dinic();
ans = min(ans, mx * c + res * d);
}
printf("%lld\n", ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 10272kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 10048kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 87ms
memory: 10248kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
122641470998
result:
wrong answer 1st numbers differ - expected: '109972100048', found: '122641470998'