#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
int n, m;
cin >> n >> m;
vector<string> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int maybeans = 0, mightbeans = 0;
vector<vector<bool>> gradea(n, vector<bool>(m, false));
for (int i = 0; i < n; i++) {
for (int j = 0; j + 2 < m; j++) {
if (v[i][j] == 'R' && v[i][j+1] == 'G' && v[i][j+2] == 'W') {
if (!gradea[i][j] && !gradea[i][j+1] && !gradea[i][j+2]) {
gradea[i][j] = gradea[i][j+1] = gradea[i][j+2] = true;
maybeans++;
}
}
}
}
for (int i = 0; i + 2 < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == 'R' && v[i+1][j] == 'G' && v[i+2][j] == 'W') {
if (!gradea[i][j] && !gradea[i+1][j] && !gradea[i+2][j]) {
gradea[i][j] = gradea[i+1][j] = gradea[i+2][j] = true;
maybeans++;
}
}
}
}
vector<vector<bool>> a1(n, vector<bool>(m, false));
for (int i = 0; i + 2 < n; i++) {
for (int j = 0; j < m; j++) {
if (v[i][j] == 'R' && v[i+1][j] == 'G' && v[i+2][j] == 'W') {
if (!a1[i][j] && !a1[i+1][j] && !a1[i+2][j]) {
a1[i][j] = a1[i+1][j] = a1[i+2][j] = true;
mightbeans++;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j + 2 < m; j++) {
if (v[i][j] == 'R' && v[i][j+1] == 'G' && v[i][j+2] == 'W') {
if (!a1[i][j] && !a1[i][j+1] && !a1[i][j+2]) {
a1[i][j] = a1[i][j+1] = a1[i][j+2] = true;
mightbeans++;
}
}
}
}
cout << max(maybeans, mightbeans) << "\n";
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |