#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
#define sped_up ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const ll INF = (ll)1e9 + 1, INFL = (ll)1e18 + 1;
const ll mod = (ll)1e9 + 7, MAXN = (ll)3004;
char a[MAXN][MAXN];
ll dp[MAXN][MAXN];
int main () {
sped_up;
ll n, m;
cin >> n >> m;
for (int i = 3; i < n + 3; i++) {
for (int j = 3; j < m + 3; j++) cin >> a[i][j];
}
for (int i = 3; i < n + 3; i++) {
for (int j = 3; j < m + 3; j++) {
ll ok = 0, ok1 = 0;
if (a[i][j] == 'W' && a[i][j - 1] == 'G' && a[i][j - 2] == 'R') ok = 1;
if (a[i][j] == 'W' && a[i - 1][j] == 'G' && a[i - 2][j] == 'R') ok1 = 1;
dp[i][j] = max({dp[i - 1][j] + dp[i][j - 3] - dp[i - 1][j - 3] + ok, dp[i - 3][j] + dp[i][j - 1] - dp[i - 3][j - 1] + ok1, dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]});
}
}
cout << dp[n + 2][m + 2];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |