제출 #330207

#제출 시각아이디문제언어결과실행 시간메모리
330207casperwangDango Maker (JOI18_dango_maker)C++14
33 / 100
47 ms21516 KiB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int MAXN = 3000;
int n, m;
string mp[MAXN+1], ss;
int p[MAXN+1][MAXN+1];
int a, b;
int ans;
vector <vector<int>> path;
bool sy[MAXN+1];
bool vis[MAXN+1];

bool dfs(int now) {
  vis[now] = 1;
  for (int i : path[now]) {
    if (!sy[i] || (!vis[sy[i]] && dfs(sy[i]))) {
      sy[i] = now;
      return 1;
    }
  }
  return 0;
}

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> ss;
    mp[i] = ' ' + ss;
  }
  path.pb(vector<int>());
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (i >= 3 && mp[i][j] == 'W' && mp[i-1][j] == 'G' && mp[i-2][j] == 'R') {
        a++;
        p[i][j] = p[i-1][j] = p[i-2][j] = a;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      if (j >= 3 && mp[i][j] == 'W' && mp[i][j-1] == 'G' && mp[i][j-2] == 'R') {
        b++, path.pb(vector<int>());
        if (p[i][j  ]) path[b].pb(p[i][j  ]);
        if (p[i][j-1]) path[b].pb(p[i][j-1]);
        if (p[i][j-2]) path[b].pb(p[i][j-2]);
      }
    }
  }
  ans = a+b;
  for (int i = 1; i <= b; i++) {
    for (int j = 1; j <= b; j++) vis[j] = 0;
    vis[i] = 1;
    for (int j : path[i]) {
      if (!sy[j] || (!vis[sy[j]] && dfs(sy[j]))) {
        sy[j] = i;
        ans--;
        break;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...