#include <bits/stdc++.h>
using namespace std;
#define inf 0x3F3F3F3F
const int MXN = 3e3 + 5;
char a[MXN][MXN];
int used[MXN][MXN];
void _()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> a[i][j];
auto check1 = [&](int x, int y)
{
if (y + 2 >= m) return false;
return !used[x][y] && !used[x][y + 1] && !used[x][y + 2] && a[x][y] == 'R' && a[x][y + 1] == 'G' && a[x][y + 2] == 'W';
};
auto check2 = [&](int x, int y)
{
if (x + 2 >= n) return false;
return !used[x][y] && !used[x + 1][y] && !used[x + 2][y] && a[x][y] == 'R' && a[x + 1][y] == 'G' && a[x + 2][y] == 'W';
};
auto cnt1 = [&](int x, int y)
{
int res = 0;
while (x < n && y >= 0 && check1(x, y)) x++, y--, res++;
return res;
};
auto cnt2 = [&](int x, int y)
{
int res = 0;
while (x < n && y >= 0 && check2(x, y)) x++, y--, res++;
return res;
};
auto mark1 = [&](int x, int y)
{
int res = 0;
while (x < n && y >= 0 && check1(x, y)) used[x][y] = used[x][y + 1] = used[x][y + 2] = 1, x++, y--;
return res;
};
auto mark2 = [&](int x, int y)
{
int res = 0;
while (x < n && y >= 0 && check2(x, y)) used[x][y] = used[x + 1][y] = used[x + 2][y] = 1, x++, y--;
return res;
};
int res = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
int A = cnt1(i, j), B = cnt2(i, j);
if (A >= B) res += A, mark1(i, j);
else res += B, mark2(i, j);
}
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) _();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |