QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#690658 | #5114. Cells Coloring | QFshengxiu | WA | 477ms | 13280kb | C++23 | 3.3kb | 2024-10-31 00:19:03 | 2024-10-31 00:19:04 |
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: 1ms
memory: 9656kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 9704kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 130ms
memory: 10556kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109972100048
result:
ok 1 number(s): "109972100048"
Test #4:
score: 0
Accepted
time: 173ms
memory: 10548kb
input:
250 250 62722280 506434 *.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..* .*..********..*...*..****...
output:
8437726048
result:
ok 1 number(s): "8437726048"
Test #5:
score: 0
Accepted
time: 465ms
memory: 13264kb
input:
250 250 85956327 344333 ..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..** .........*......*.*.........
output:
18268031127
result:
ok 1 number(s): "18268031127"
Test #6:
score: -100
Wrong Answer
time: 477ms
memory: 13280kb
input:
250 250 768323813 489146 ...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*...... ...................*.......
output:
26645125505
result:
wrong answer 1st numbers differ - expected: '25999088192', found: '26645125505'