QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#591666 | #5114. Cells Coloring | confirm14478 | WA | 627ms | 14104kb | C++20 | 2.0kb | 2024-09-26 17:07:46 | 2024-09-26 17:07:47 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define int long long
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
#define debug cout<<'*'<<'\n'
const int N = 2e5+50, M = 2e6+50;
const int mod = 1e9 + 7, inf = 2e18;
using namespace std;
struct Edge
{
int to, next, w;
}edge[M * 2];
int tot = 1, head[N];
int n_all, s, t;
void add(int u, int v, int w)
{
edge[++tot].to = v;
edge[tot].next = head[u];
edge[tot].w = w;
head[u] = tot;
}
int d[N],cur[N];
void bfs()//分层
{
for (int i = 1; i <= n_all; i++)d[i] = -1,cur[i]=head[i];
d[s] = 0;
queue<int>q;
q.push(s);
while (!q.empty())
{
int u = q.front();
q.pop();
for (int i = head[u]; i; i = edge[i].next)
{
int v = edge[i].to;
if (edge[i].w > 0 && d[v] == -1)
{
d[v] = d[u] + 1;
q.push(v);
}
}
}
}
int dfs(int u, int flow)//算流量
{
if (u == t)return flow;
int rmn = flow;
for (int &i = cur[u]; i&&rmn; i = edge[i].next)
{
int v = edge[i].to;
if (edge[i].w > 0 && d[v] == d[u] + 1)
{
int c = dfs(v, min(rmn, edge[i].w));
rmn -= c;
edge[i].w -= c;
edge[i ^ 1].w += c;
}
}
return flow - rmn;
}
int col[N],row[N];
void solve() {
int n,m,a,b;
cin>>n>>m>>a>>b;
n_all = n+m+2;
s=n+m+1,t=n+m+2;
tot=1;
for(int i=1;i<=n;i++) {
add(s,i,0);
col[i]=tot;
add(i,s,0);
}
for(int j=1;j<=m;j++) {
add(j+n,t,0);
row[j]=tot;
add(t,j+n,0);
}
int cnt=0;
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
char c;
cin>>c;
if(c=='.') {
add(i,j+n,1);
add(j+n,i,0);
cnt++;
}
}
}
int ans=b*cnt;
for(int k=1;k<=min(n,m);k++) {
for(int i=1;i<=n;i++)edge[col[i]].w+=1;
for(int j=1;j<=m;j++)edge[row[j]].w+=1;
do {
bfs();
cnt-=dfs(s,inf);
}while(d[t]!=-1);
ans=min(ans,a*k+b*cnt);
}
cout<<ans;
}
signed main()
{
//freopen("C:\\Users\\win11\\Desktop\\test.txt", "r", stdin);
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int T = 1;
//cin >> T;
while (T--)solve();
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 11780kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11816kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 142ms
memory: 13800kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109972100048
result:
ok 1 number(s): "109972100048"
Test #4:
score: 0
Accepted
time: 225ms
memory: 13900kb
input:
250 250 62722280 506434 *.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..* .*..********..*...*..****...
output:
8437726048
result:
ok 1 number(s): "8437726048"
Test #5:
score: 0
Accepted
time: 612ms
memory: 13860kb
input:
250 250 85956327 344333 ..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..** .........*......*.*.........
output:
18268031127
result:
ok 1 number(s): "18268031127"
Test #6:
score: 0
Accepted
time: 627ms
memory: 14064kb
input:
250 250 768323813 489146 ...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*...... ...................*.......
output:
25999088192
result:
ok 1 number(s): "25999088192"
Test #7:
score: 0
Accepted
time: 139ms
memory: 14104kb
input:
250 250 865365220 7248935 .....**.*.***...**.**...*.**.*****..****.**.**.*...*..**....*.**.*..**..*..*.****....***.***.*...*.*.*.**..****.***.*.**..*****.**..*.*.***..***.*..*.*..*......*.*******.*******.*..*.******.....**.***...*****...*...**....**.**.*...*...**.*.*****...*. *..*.**.*...****.*.**.*...
output:
97440874100
result:
ok 1 number(s): "97440874100"
Test #8:
score: 0
Accepted
time: 45ms
memory: 11824kb
input:
153 225 485767021 308782855 .*.**.***..***..***..****.*****.***.....*.***.****.*.*......**......****.****.**.******...**...*.***.*..**.*****.****....*.*.*...**..****.**.******....*....****....**.*.*****.**.**.**.***...*.**.*.**.****.*.*....*.*****...*** *.*....*...*.*..*.*****.***.***.***.***..*.***...
output:
54405906352
result:
ok 1 number(s): "54405906352"
Test #9:
score: -100
Wrong Answer
time: 2ms
memory: 9760kb
input:
17 20 823772868 410753944 .....*......**...... .......*............ ...............*.... ......*............. ...................* *........*.*..*..... .....*.............* ..*..........*.*.... .......*............ ...**...........**.* .................... **......**.......*.. .*.............*.... ....
output:
20986955804
result:
wrong answer 1st numbers differ - expected: '16062438436', found: '20986955804'