This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define FordE(i, l, r) for (int i = l; i >= r; i--)
#define Fora(v, a) for (auto v: a)
#define bend(a) a.begin(), a.end()
#define isz(a) ((signed)a.size())
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;
typedef vector <vi> vvi;
const int N = 3e3 + 5;
int n, m;
char a[N][N];
vpii b;
int dp[N][2];
int ans;
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("KEK.inp", "r", stdin);
// freopen("KEK.out", "w", stdout);
cin >> n >> m;
ForE(i, 1, n){
ForE(j, 1, m){
cin >> a[i][j];
}
}
ForE(dia, 2, n + m - 2){
b.resize(1);
memset(dp, 0, sizeof(dp));
ForE(i, 1, n){
int j = dia - i;
if (m < j or j < 1){
continue;
}
b.emplace_back(i, j);
}
For(i, 1, isz(b)){
dp[i][0] = max(dp[i][0], dp[i - 1][0]);
if (i >= 2) dp[i][0] = max(dp[i][0], dp[i - 2][1]);
if (b[i].se + 2 <= m and a[b[i].fi][b[i].se] == 'R' and a[b[i].fi][b[i].se + 1] == 'G' and a[b[i].fi][b[i].se + 2] == 'W'){
dp[i][0] = max(dp[i][0], dp[i - 1][0] + 1);
}
dp[i][1] = max(dp[i][1], dp[i][0]);
dp[i][1] = max(dp[i][1], dp[i - 1][1]);
if (b[i].fi + 2 <= n and a[b[i].fi][b[i].se] == 'R' and a[b[i].fi + 1][b[i].se] == 'G' and a[b[i].fi + 2][b[i].se] == 'W'){
dp[i][1] = max(dp[i][1], dp[i - 1][1] + 1);
}
}
ans += dp[isz(b) - 1][1];
}
cout << ans << endl;
}
/*
==================================================+
INPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
OUTPUT: |
--------------------------------------------------|
--------------------------------------------------|
==================================================+
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |