QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#65124 | #5114. Cells Coloring | LI | WA | 3ms | 3380kb | C++14 | 1.5kb | 2022-11-27 17:37:58 | 2022-11-27 17:38: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) {
cout << i << '\n';
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++) {
print();
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: 0
Wrong Answer
time: 3ms
memory: 3380kb
input:
3 4 2 1 .*** *..* **..
output:
1 0 0 0 0 1 1 0 0 0 1 1 1 2 3 0 0 0 0 0 0 1 0 0 0 0 1 1 2 3 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4
result:
wrong answer 1st numbers differ - expected: '4', found: '1'