#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ertunt return
#define vodka void
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
char s[n + 1][m + 1];
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) cin >> s[i][j];
}
vector<vector<ll>> vis[n + m + 1];
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
vector<ll> u;
u.pb(0);
if ((i > 1 and s[i - 1][j] == 'R') and s[i][j] == 'G' and (i < n and s[i + 1][j] == 'W')){
u.pb(1);
}
if ((j > 1 and s[i][j - 1] == 'R') and s[i][j] == 'G' and(j < m and s[i][j + 1] == 'W')){
u.pb(2);
}
vis[i + j].pb(u);
}
}
ll ans = 0;
vector<ll> dp(3), dp1(3);
for (ll i = 2; i <= n + m; i++) {
fill(dp.begin(), dp.end(), 0);
for (auto v : vis[i]) {
dp1 = dp;
fill(dp.begin(), dp.end(), 0);
for (auto x : v) {
if (x == 0) dp[x] = max({dp1[0], dp1[1], dp1[2]});
if (x == 1) dp[x] = max(dp1[0], dp1[1]) + 1;
if (x == 2) dp[x] = max(dp1[0], dp1[2]) + 1;
}
}
ans += max({dp[0], dp[1], dp[2]});
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |