#include <bits/stdc++.h>
#define int long long
#define iamaperson int main() {\
preprocess();\
int t = 1; while (t--) solve();\
}
using namespace std;
void preprocess() {} // just in case!!!!1
void solve() {
int n, m; cin >> n >> m;
vector<pair<int, int>> v, h;
vector<string> g(n); for (auto &x : g) cin >> x;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m-2; ++j) {
if (g[i][j] == 'R' && g[i][j+1] == 'G' && g[i][j+2] == 'W') v.push_back({i, j});
}
}
for (int i = 0; i < n-2; ++i) {
for (int j = 0; j < m; ++j) {
if (g[i][j] == 'R' && g[i+1][j] == 'G' && g[i+2][j] == 'W') h.push_back({i, j});
}
}
int a = v.size(), b = h.size(), ans = 0;
for (int i = 0; i < 1<<a; ++i) {
for (int j = 0; j < 1<<b; ++j) {
vector<pair<int, int>> vs, hs;
for (int k = 0; k < a; ++k) if (i&(1<<k)) vs.push_back(v[k]);
for (int k = 0; k < b; ++k) if (j&(1<<k)) hs.push_back(h[k]);
for (auto [x1, y1] : vs) {
for (auto [x2, y2] : hs) {
if ((x1 == x2 && y1 == y2) || (x1 == x2+1 && y1+1 == y2) || (x1 == x2+2 && y1+2 == y2)) goto End;
}
}
ans = max(ans, (int)(vs.size() + hs.size()));
End:;
}
}
cout << ans;
}
#undef int
iamaperson
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |