QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#69744 | #5114. Cells Coloring | zhuibao | AC ✓ | 644ms | 7956kb | C++20 | 2.6kb | 2022-12-30 21:18:13 | 2022-12-30 21:18:14 |
Judging History
answer
#define _CRT_SECURE_NO_WARNINGS
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<unordered_map>
#include<unordered_set>
#include<bits/stdc++.h>
#include<array>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pi;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(ll i=a;i<=n;i++)
#define ref(i,n,a) for(ll i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"No"<<endl;return;}
#define YES {cout<<"yes"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("out.txt", ios::out);
//ifstream fin("in.txt", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------
const int N = 510, M = 2e5;
int h[N], dep[N], cur[N], e[M], ne[M], w[M];
int n, m, S, T, idx, c, d;
char g[300][300];
void add(int a, int b, int c)
{
e[idx] = b, ne[idx] = h[a], w[idx] = c, h[a] = idx++;
}
bool bfs()
{
mem(dep, 0);
queue<int>q;
q.emplace(S);
dep[S] = 1;
while (q.size())
{
int t = q.front();
q.pop();
cur[t] = h[t]; //重置当前弧
for (int i = h[t]; ~i; i = ne[i])
{
int j = e[i];
if (w[i] > 0 && !dep[j]) //可用流量大于0,没被遍历过
{
q.emplace(j);
dep[j] = dep[t] + 1;
}
}
}
return dep[T] > 0;
}
int dfs(int x, int lim) //遍历到的点,最大流量限制
{
if (x == T)return lim;
int k = 0, res = 0; //子节点最大流量k,总共可以流过res
for (int i = cur[x]; ~i && lim > 0; i = ne[i])
{
int j = e[i];
cur[x] = i; //当前弧优化
if (w[i] && dep[x] + 1 == dep[j])
{
k = dfs(j, min(lim, w[i]));
if (!k)dep[j] = 0;
w[i] -= k; //更新正向边
w[i ^ 1] += k; //更新反向边
lim -= k;
res += k;
}
}
return res;
}
void build(int k)
{
mem(h, -1);
idx = 0;
fer(i, 1, n)
{
add(S, i, k);
add(i, S, 0);
}
for (int i = n + 1; i <= n + m; i++)
{
add(i, T, k);
add(T, i, 0);
}
fer(i, 1, n)
{
fer(j, 1, m)
{
if (g[i][j] == '*')continue;
add(i, n + j, 1);
add(n + j, i, 0);
}
}
}
void solve()
{
cin >> n >> m >> c >> d;
S = n + m + 1, T = S + 1;
int cnt = 0;
fer(i, 1, n)
{
fer(j, 1, m)
{
cin >> g[i][j];
if (g[i][j] == '.')cnt++;
}
}
int ans = 1e18;
fer(k, 0, max(n, m))
{
build(k);
int z = 0;
while (bfs())z += dfs(S, 1e9);
int res = c * k + d * (cnt - z);
ans = min(ans, res);
}
cout << ans << endl;
}
AC
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5420kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5596kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: 0
Accepted
time: 309ms
memory: 6412kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
109972100048
result:
ok 1 number(s): "109972100048"
Test #4:
score: 0
Accepted
time: 396ms
memory: 6388kb
input:
250 250 62722280 506434 *.**.***.*.*....*....*...**.*..**..****.*.*..*.*.*..*.....**..*.*.*.*****.*.**..*.**....***..*..*.*.*.**.*..*..*.**..*...**....**..*.*.***.*****.*****.***..**.***.****....*.*.**.**.*...****....*..*.**.**********.......********...***.**..*.....**.*..* .*..********..*...*..****...
output:
8437726048
result:
ok 1 number(s): "8437726048"
Test #5:
score: 0
Accepted
time: 639ms
memory: 7268kb
input:
250 250 85956327 344333 ..*.............*...*.....*...*..........*.........*...*.......*..***......*.*........*.*........*........*..*..*.............*.*........*....*..*................***...................*..*.............*..*.....*..**..............*..*......*.....*..** .........*......*.*.........
output:
18268031127
result:
ok 1 number(s): "18268031127"
Test #6:
score: 0
Accepted
time: 644ms
memory: 7956kb
input:
250 250 768323813 489146 ...*................*...........*.................*..***..*.......*..*......*.................*...*.........*.*.*.*...*.*.*.*.*.......*........*.............*...............*..*.............*.*...*.....................**.....**.....*.*........*...... ...................*.......
output:
25999088192
result:
ok 1 number(s): "25999088192"
Test #7:
score: 0
Accepted
time: 299ms
memory: 6340kb
input:
250 250 865365220 7248935 .....**.*.***...**.**...*.**.*****..****.**.**.*...*..**....*.**.*..**..*..*.****....***.***.*...*.*.*.**..****.***.*.**..*****.**..*.*.***..***.*..*.*..*......*.*******.*******.*..*.******.....**.***...*****...*...**....**.**.*...*...**.*.*****...*. *..*.**.*...****.*.**.*...
output:
97440874100
result:
ok 1 number(s): "97440874100"
Test #8:
score: 0
Accepted
time: 98ms
memory: 6128kb
input:
153 225 485767021 308782855 .*.**.***..***..***..****.*****.***.....*.***.****.*.*......**......****.****.**.******...**...*.***.*..**.*****.****....*.*.*...**..****.**.******....*....****....**.*.*****.**.**.**.***...*.**.*.**.****.*.*....*.*****...*** *.*....*...*.*..*.*****.***.***.***.***..*.***...
output:
54405906352
result:
ok 1 number(s): "54405906352"
Test #9:
score: 0
Accepted
time: 3ms
memory: 5364kb
input:
17 20 823772868 410753944 .....*......**...... .......*............ ...............*.... ......*............. ...................* *........*.*..*..... .....*.............* ..*..........*.*.... .......*............ ...**...........**.* .................... **......**.......*.. .*.............*.... ....
output:
16062438436
result:
ok 1 number(s): "16062438436"
Test #10:
score: 0
Accepted
time: 104ms
memory: 5812kb
input:
227 129 426009970 614728889 *..****..*..*.********.*.*..***.*.*..**..*.***.**.**.***..*.***..*..*.***.*.*.**..*****.**..***.*.****.**.***.****..**.**.*.**.** *...*****.**....****..*....*.*.**.*****.*..*****...*...**...******..****.*..**...***.*.*.*..*.*.*..*.******.*****..*.**********.* .*.*..**..**...
output:
49843166490
result:
ok 1 number(s): "49843166490"
Test #11:
score: 0
Accepted
time: 160ms
memory: 6396kb
input:
170 219 28214303 818736602 *..*....*..*..*....**.*...*..*.**....**.*..*........*.**.....*....*.*..*..*.**.....*..***......*.....*...*........**.*.*.***...*........**..**....***...**....*.*..........**....*....**.***....*.*.*..*..***.....*.*..***. .*.*.....**...*..*....*.*....*.*.**.........*...*..*....
output:
4514288480
result:
ok 1 number(s): "4514288480"
Test #12:
score: 0
Accepted
time: 0ms
memory: 5536kb
input:
221 2 186883458 764869506 *. .* ** .* ** ** *. .* .* .* *. .* .. ** ** *. .. .* .* ** ** *. .* *. .. *. ** .* ** .. ** .. ** .. .* *. ** .* .* ** .. .* ** ** ** ** .* .. .* .* .. ** .* ** .* ** .. ** *. ** .. .* *. .* ** .* ** .. .* ** .* ** ** .* ** ** .* ** ** .. .. .* ** .. ** .* *. *. *. *. *. *...
output:
17753928510
result:
ok 1 number(s): "17753928510"
Test #13:
score: 0
Accepted
time: 2ms
memory: 7400kb
input:
28 2 127093639 70848307 .* .* ** .. .. .* ** *. ** .. ** *. *. ** *. .. .* .* *. ** ** .* ** .. *. .* ** **
output:
1468878336
result:
ok 1 number(s): "1468878336"
Test #14:
score: 0
Accepted
time: 1ms
memory: 5460kb
input:
142 1 465099485 99077573 * . . * * * * * . * . * . * . . . . * * * * * . * . . * * * . * . . . . . * * * * * * * * . * . * . . * * . * * * * . . * * . * * * * * * * . . . * * * * * * . * . * . * * * * . . . * * . * . . * . * . . . * . . * . . . . * . * . * * * * * * * . * * * * . * . . . . * . * * ....
output:
5845576807
result:
ok 1 number(s): "5845576807"
Test #15:
score: 0
Accepted
time: 401ms
memory: 7792kb
input:
250 250 420456041 0 ...*****.....****......*.**..*..*.**.**...*.***..**.*......*.*.....**..*..**.*..***.*.****.*.**.*.....**..*.*.**....**..***......*...***..*...****.*****.*.***.**.*.*...****.***..*...*.*.**.***..*.***.*.****.*.*...**....***....*.*.**....***...*.***... *.**...**.**...*..*..*.*.*.**...
output:
0
result:
ok 1 number(s): "0"
Test #16:
score: 0
Accepted
time: 631ms
memory: 7136kb
input:
250 250 0 577876919 .............**.*.....*.....*.*..*.......*...*.................**........*........*....*...*.......*...*........................*.......*.....*.*.*.......*........................*...............*..*.*....*.*.*..................*..................... ...*...*...................*....
output:
0
result:
ok 1 number(s): "0"
Test #17:
score: 0
Accepted
time: 7ms
memory: 5632kb
input:
250 250 708109405 398540228 ********************************************************************************************************************************************************************************************************************************************************** *********************...
output:
0
result:
ok 1 number(s): "0"
Test #18:
score: 0
Accepted
time: 638ms
memory: 7508kb
input:
250 250 1000000000 1000000 .......................................................................................................................................................................................................................................................... .........................
output:
62500000000
result:
ok 1 number(s): "62500000000"
Test #19:
score: 0
Accepted
time: 644ms
memory: 7568kb
input:
250 250 1000000000 10000000 .......................................................................................................................................................................................................................................................... ........................
output:
250000000000
result:
ok 1 number(s): "250000000000"