Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define debug(tl) cerr<<#tl<<' '<<tl<<'\n';
- #include "bits/stdc++.h"
- using namespace std;
- #define all(mask) mask.begin(), mask.end()
- typedef long long ll;
- typedef pair<ll, ll> pll;
- typedef pair<int, int> pii;
- typedef long double ld;
- const int MAXN = 1e4;
- vector<int> gr[MAXN];
- vector<int> used(MAXN), mpair(MAXN, -1);
- bool kuhn(int v) {
- if (used[v]) return false;
- used[v] = true;
- for (auto u : gr[v]) {
- if (mpair[u] == -1 || kuhn(mpair[u])) {
- mpair[u] = v;
- return true;
- }
- }
- return false;
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- freopen("dominoes.in", "r", stdin);
- freopen("dominoes.out", "w", stdout);
- int n, m, a0, b0, cur = 0;
- cin >> n >> m >> a0 >> b0;
- vector<vector<char>> a(n + 1, vector<char>(m + 1, '.'));
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- cin >> a[i][j];
- cur += a[i][j] == '*';
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < m; j++) {
- if (a[i][j] == '*') {
- if ((i + j) % 2) {
- if (a[i][j + 1] == '*') {
- gr[i * m + j].push_back(i * m + 1 + j);
- }
- if (a[i + 1][j] == '*') {
- gr[i * m + j].push_back(i * m + m + j);
- }
- }
- else {
- if (a[i][j + 1] == '*') {
- gr[i * m + j + 1].push_back(i * m + j);
- }
- if (a[i + 1][j] == '*') {
- gr[(i + 1) * m + j].push_back(i * m + j);
- }
- }
- }
- }
- }
- for (int i = 0; i < MAXN; i++) {
- used.assign(MAXN, 0);
- kuhn(i);
- }
- int cnt = 0;
- for (int i = 0; i < MAXN; i++) {
- if (mpair[i] != -1) {
- cnt++;
- }
- }
- cout << min(cnt * a0 + cur * b0 - cnt * 2 * b0, b0 * cur);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement