QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#418630 | #5114. Cells Coloring | xqbf# | WA | 131ms | 7368kb | C++14 | 2.2kb | 2024-05-23 14:54:35 | 2024-05-23 14:54:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
const int MAXN = 65050;
struct edg{ int pos, cap, rev; };
struct Dinic{
vector <edg> gph[MAXN];
int dis[MAXN], pnt[MAXN], flow;
void clear(){ for (int i = 0; i < MAXN; i++) gph[i].clear(); }
pii add_edge(int s, int e, int x){
gph[s].push_back({e, x, (int) gph[e].size()});
gph[e].push_back({s, 0, (int) gph[s].size() - 1});
return make_pair(s, gph[s].size() - 1);
}
bool bfs(int src, int sink){
memset(dis, 0, sizeof dis);
memset(pnt, 0, sizeof pnt);
queue <int> que;
que.push(src), dis[src] = 1;
while (que.size()){
int x = que.front(); que.pop();
for (auto &e : gph[x]){
if (e.cap > 0 && !dis[e.pos]){
dis[e.pos] = dis[x] + 1;
que.push(e.pos);
}
}
}
return dis[sink] > 0;
}
int dfs(int x, int sink, int f){
if (x == sink) return f;
for (; pnt[x] < gph[x].size(); pnt[x]++){
edg e = gph[x][pnt[x]];
if (e.cap > 0 && dis[e.pos] == dis[x] + 1){
int w = dfs(e.pos, sink, min(f, e.cap));
if (w){
gph[x][pnt[x]].cap -= w;
gph[e.pos][e.rev].cap += w;
return w;
}
}
}
return 0;
}
int max_flow(int src, int sink){
while (bfs(src, sink)){
int r;
while ((r = dfs(src, sink, 2e9))) flow += r;
}
return flow;
}
} G;
vector <pii> evec;
string mp[550];
int n, m, c, d, S, T, tot;
int main(){
ios :: sync_with_stdio(false), cin.tie(0);
cin >> n >> m >> c >> d;
for (int i = 1; i <= n; i++)
cin >> mp[i];
S = 1, T = 2;
for (int i = 1; i <= n; i++)
evec.push_back(G.add_edge(S, 2 + i, 1));
for (int i = 1; i <= m; i++)
evec.push_back(G.add_edge(2 + n + i, T, 1));
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++){
int id = (i - 1) * m + j;
if (mp[i][j - 1] == '*') continue;
tot++;
G.add_edge(2 + i, 2 + n + m + id, 1);
G.add_edge(2 + n + m + id, 2 + n + j, 1);
}
long long ret = tot * d;
for (int k = 1; k <= max(n, m); k++){
int z = tot - G.max_flow(S, T);
ret = min(ret, 1ll * c * k + 1ll * d * z);
for (auto e : evec) G.gph[e.first][e.second].cap += 1;
}
cout << ret << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5624kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5780kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 131ms
memory: 7368kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
-725361838
result:
wrong answer 1st numbers differ - expected: '109972100048', found: '-725361838'