QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65129 | #5114. Cells Coloring | LI | WA | 969ms | 3780kb | C++14 | 1.5kb | 2022-11-27 17:42:40 | 2022-11-27 17:42:41 |
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++) {
if(p[j]) {
Map[p[j]][j] = 0;
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3476kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3272kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 969ms
memory: 3780kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
110218087642
result:
wrong answer 1st numbers differ - expected: '109972100048', found: '110218087642'