QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#690654 | #5114. Cells Coloring | QFshengxiu | WA | 84ms | 9592kb | C++23 | 3.3kb | 2024-10-31 00:17:23 | 2024-10-31 00:17:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
// #define int long long
#define QF ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
constexpr int N = 1e5 + 10;
constexpr int M = 1e5 + 10;
const int inf = 1e9;
int n, m, s, t, tot = 1, ans;
int head[N], now[N], dep[N];
bool used[N];
string st[N];
struct edge
{
int v, w, nxt;
} edges[M << 1];
void add(int u, int v, int w)
{
edges[++tot] = {v, w, head[u]};
head[u] = tot;
}
void addedge(int u, int v, int w)
{
used[u] = true;
used[v] = true;
add(u, v, w);
add(v, u, 0);
}
bool bfs()
{
memset(dep, 0, sizeof(dep));
queue<int> q;
q.push(s);
dep[s] = 1;
while (!q.empty())
{
auto u = q.front();
q.pop();
for (int i = head[u]; i; i = edges[i].nxt)
{
auto [v, w, x] = edges[i];
if (w && !dep[v])
{
dep[v] = dep[u] + 1;
q.push(v);
if (v == t)
return true;
}
}
}
return false;
}
int dfs(int u, int flow)
{
if (u == t)
{
return flow;
}
int res = 0;
for (int i = now[u]; i && flow; i = edges[i].nxt)
{
now[u] = i;
auto [v, w, x] = edges[i];
if (w && dep[v] == dep[u] + 1)
{
int k = dfs(v, min(flow, w));
if (!k)
{
dep[v] = 0;
}
res += k;
flow -= k;
edges[i].w -= k;
edges[i ^ 1].w += k;
}
}
return res;
}
void clear()
{
tot = 1;
memset(head, 0, sizeof(head));
memset(used, 0, sizeof(used));
s = 0, t = 0;
}
void solve()
{
int c, d;
cin >> n >> m >> c >> d;
for (int i = 1; i <= n; i++)
{
cin >> st[i];
st[i] = " " + st[i];
}
s = 1e5, t = s + 1;
int all = 0;
for (int j = 1; j <= n; j++)
{
addedge(s, j, 1);
for (int i = 1; i <= m; i++)
{
if (st[j][i] != '*')
{
addedge(j, i + n, 1);
all++;
}
}
}
for (int j = 1; j <= m; j++)
{
addedge(j + n, t, 1);
}
int minn = inf;
ans = 0;
while (bfs())
{
for (int i = 1; i <= n + m; i++)
{
now[i] = head[i];
}
now[s] = head[s];
now[t] = head[t];
ans += dfs(s, inf);
}
int nx = c + (all - ans) * d;
minn = nx;
for (int i = 2; i <= max(n, m); i++)
{
for (int x = head[s]; x; x = edges[x].nxt)
{
edges[x].w++;
}
for (int x = head[t]; x; x = edges[x].nxt)
{
edges[x ^ 1].w++;
}
while (bfs())
{
for (int w = 1; w <= n + m; w++)
{
now[w] = head[w];
}
now[s] = head[s];
now[t] = head[t];
ans += dfs(s, inf);
}
// cout << ans << endl;
nx = i * c + (all - ans) * d;
minn = min(minn, nx);
}
cout << minn << endl;
}
signed main()
{
QF;
int T = 1;
for (int i = 1; i <= T; i++)
{
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 7652kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 1ms
memory: 8084kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 84ms
memory: 9592kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
-2142437838
result:
wrong answer 1st numbers differ - expected: '109972100048', found: '-2142437838'