QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65125 | #5114. Cells Coloring | LI | TL | 2ms | 3488kb | C++14 | 1.5kb | 2022-11-27 17:38:59 | 2022-11-27 17:39:01 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
char s[255][255];
int a[255], b[255];
ll n, m, c, d;
int M, N;
int Map[255][255];
int p[255];
int vis[255];
void print() {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
cout << Map[i][j] << ' ';
}
cout << '\n';
}
}
bool match(int i) {
for(int j = 1; j <= N; j++) {
if(Map[i][j] && !vis[j]) {
vis[j] = 1;
if(p[j] == 0 || match(p[j])) {
p[j] = i;
return true;
}
}
}
return 0;
}
ll ans = 0;
void fk() {
int cnt = 0;
ll tmp = ans;
for(int i = 1; i <= M; i++) {
memset(p, 0, sizeof(p));
for (int j = 1; j <= M; j++) {
memset(vis, 0, sizeof(vis));
match(j);
}
int ok = 0;
// for(int j = 1; j <= M; j++) cout << p[j] << ' ';cout << '\n';
for(int j = 1; j <= N; j++) {
Map[p[j]][j] = 0;
if(p[j]) {
ok = 1;
p[j] = 0;
tmp -= d;
}
}
if(ok) {
tmp += c;
ans = min(ans, tmp);
}
}
}
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> m >> c >> d;
N = m, M = n;
for(int i = 1; i <= n; i++) cin >> s[i] + 1;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(s[i][j] == '.') {
ans += d;
a[i]++, b[j]++;
Map[i][j] = 1;
}
}
}
ll k = max(*max_element(a + 1, a + 251), *max_element(b + 1, b + 251));
if (k == 0) {
cout << "0\n";
return 0;
}
fk();
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3352kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3488kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Time Limit Exceeded
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...