QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#217408 | #5114. Cells Coloring | ucup-team1001 | WA | 220ms | 5364kb | C++20 | 3.0kb | 2023-10-16 20:40:30 | 2023-10-16 20:40:30 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define irep(i,l,r) for(int i = l; i <= r; ++i)
const int itinf = 1e9;
inline char rc(){
char ch = getchar();
while(1){
if(ch == '*' || ch == '.')return ch;
ch = getchar();
}
}
inline ll read(){
char ch = getchar();
ll s = 0; bool w = 0;
while(!isdigit(ch)){if(ch == '-')w = 1;ch = getchar();}
while(isdigit(ch))s = (s << 3) + (s << 1) + (ch ^ 48), ch = getchar();
return w ? - s : s;
}
template<class T>
struct Flow {
const int n;
struct Edge {
int to;
T cap;
Edge(int to, T cap) : to(to), cap(cap) {}
};
std::vector<Edge> e;
std::vector<std::vector<int>> g;
std::vector<int> cur, h;
Flow(int n) : n(n), g(n) {}
bool bfs(int s, int t) {
h.assign(n, -1);
std::queue<int> que;
h[s] = 0;
que.push(s);
while (!que.empty()) {
const int u = que.front();
que.pop();
for (int i : g[u]) {
auto [v, c] = e[i];
if (c > 0 && h[v] == -1) {
h[v] = h[u] + 1;
if (v == t) {
return true;
}
que.push(v);
}
}
}
return false;
}
T dfs(int u, int t, T f) {
if (u == t) {
return f;
}
auto r = f;
for (int &i = cur[u]; i < int(g[u].size()); ++i) {
const int j = g[u][i];
auto [v, c] = e[j];
if (c > 0 && h[v] == h[u] + 1) {
auto a = dfs(v, t, std::min(r, c));
e[j].cap -= a;
e[j ^ 1].cap += a;
r -= a;
if (r == 0) {
return f;
}
}
}
return f - r;
}
void addEdge(int u, int v, T c) {
g[u].push_back(e.size());
e.emplace_back(v, c);
g[v].push_back(e.size());
e.emplace_back(u, 0);
}
T maxFlow(int s, int t) {
T ans = 0;
while (bfs(s, t)) {
cur.assign(n, 0);
ans += dfs(s, t, std::numeric_limits<T>::max());
}
return ans;
}
};
int main(){
int n = read(), m = read(), cnt = 0;
ll c = read(), d = read();
int S = n + m, T = n + m + 1;
vector<array<int, 2>>eg;
irep(i, 0, n - 1){
irep(j, 0, m - 1){
if(rc() == '.'){
++ cnt;
eg.push_back({i, j + n});
// flow.addEdge(i,j + n,1);
}
}
}
// return 0;
ll ans = std::numeric_limits<ll>::max();
irep(k, 0, max(n, m)){
Flow<ll>flow((n + m + 2) * 2);
irep(j, 0, m - 1){
flow.addEdge(j + n, T, itinf);
}
irep(i, 0, n - 1){
flow.addEdge(S, i, k);
}
for(auto [u, v] : eg)flow.addEdge(u, v, 1);
ans = min(ans ,1ll * (cnt - flow.maxFlow(S,T)) * d + 1ll * k * c);
}
printf("%lld", ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3776kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 220ms
memory: 5364kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109628492572
result:
wrong answer 1st numbers differ - expected: '109972100048', found: '109628492572'