QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65127 | #5114. Cells Coloring | LI | WA | 959ms | 3636kb | C++14 | 2.0kb | 2022-11-27 17:40:51 | 2022-11-27 17:40:53 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 255;
const int MAXM = 255;
ll n, m, c, d;
int M, N; //M, N分别表示左、右侧集合的元素数量
int Map[MAXM][MAXN]; //邻接矩阵存图
char s[MAXN][MAXN];
int p[MAXN]; //记录当前右侧元素所对应的左侧元素
bool vis[MAXN]; //记录右侧元素是否已被访问过
bool match(int i) {
for (int j = 1; j <= N; ++j)
if (Map[i][j] && !vis[j]) {//有边且未访问
vis[j] = true; //记录状态为访问过
if (p[j] == 0 || match(p[j])) {//如果暂无匹配,或者原来匹配的左侧元素可以找到新的匹配
p[j] = i; //当前左侧元素成为当前右侧元素的新匹配
return true; //返回匹配成功
}
}
return false; //循环结束,仍未找到匹配,返回匹配失败
}
ll ans = 0;
int fk() {
int cnt = 0;
for (int i = 1; i <= M; ++i) {
memset(vis, 0, sizeof(vis)); //重置vis数组
if (match(i)) cnt++;
}
return cnt;
}
int main() {
cin.tie(nullptr) -> sync_with_stdio(false);
cin >> n >> m >> c >> d;
M = n, N = m;
for(int i = 1; i <= n; i++) {
cin >> s[i] + 1;
for (int j = 1; j <= m; j++) {
if(s[i][j] == '.') {
Map[i][j] = 1;
ans += d;
}
}
}
ll tmp = ans;
for(int i = 1; i <= max(N, M); i++) {
memset(p, 0, sizeof(p));
fk();
int x = 0;
for(int j = 1; j <= N; j++) {
if(p[j]) {
x++;
Map[p[j]][j] = 0;
}
}
if(x) {
tmp = tmp - x * d + c;
ans = min(ans, tmp);
}
else {
break;
}
}
cout << ans << '\n';
return 0;
}
/*
3 4 2 1
.***
*..*
**..
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3268kb
input:
3 4 2 1 .*** *..* **..
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 3496kb
input:
3 4 1 2 .*** *..* **..
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Wrong Answer
time: 959ms
memory: 3636kb
input:
250 250 965680874 9042302 ..**.*****..**..**.*****..***..***.**......*.***.*...***.*....*.**.*.**.*.*.****...*.******.***.************....**.*..*..***.*******.*.***.*..**..****.**.*.*..***.****..**.....***.....*.****...*...*.***..****..**.*.*******..*.*******.*.*.*.****.*.*** ....**.*******.*.******...
output:
110218087642
result:
wrong answer 1st numbers differ - expected: '109972100048', found: '110218087642'