This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<vector<int>> L;
vector<int> matched;
vector<int> used;
int cnt = 1;
int sz = 0;
int szR = 0;
bool dfs(int v) {
if (used[v] == cnt) return false;
used[v] = cnt;
for (int u : L[v]) {
if (matched[u] == -1) {
matched[u] = v;
return true;
}
if (dfs(matched[u])) {
matched[u] = v;
return true;
}
}
}
void solve() {
int n, m;
cin >> n >> m;
vector<string> d(n);
vector<vector<int>> comp(n, vector<int>(m, -1));
for (int i = 0; i < n; i++)
cin >> d[i];
for (int i = 0; i < n - 2; i++)
for (int j = 0; j < m; j++) {
if (d[i][j] == 'R' && d[i + 1][j] == 'G' && d[i + 2][j] == 'W') {
comp[i][j] = comp[i + 1][j] = comp[i + 2][j] = sz++;
}
}
L.resize(sz);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m - 2; j++) {
if (d[i][j] == 'R' && d[i][j + 1] == 'G' && d[i][j + 2] == 'W') {
int cur = szR++;
for (int dj = 0; dj < 3; dj++) {
if (comp[i][j + dj] != -1) {
L[comp[i][j + dj]].push_back(cur);
}
}
}
}
}
matched.resize(szR, -1);
used.resize(sz);
for (int v = 0; v < sz; v++) {
if (dfs(v))
cnt++;
}
cout << sz + szR - (cnt - 1);
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
Compilation message (stderr)
dango_maker.cpp: In function 'bool dfs(int)':
dango_maker.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
29 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |