This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option
#include<bits/stdc++.h>
using namespace std;
#define all(flg) flg.begin(), flg.end()
#define int long long
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define eb emplace_back
#define ii pair<int, int>
#define vi vector<int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define ld long double
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const ll mod = 1e9 + 7;
const int maxN = 3005;
const ll oo = 1e18 + 7;
int n, a[maxN];
int x, y, z, k, m;
int dp[maxN][maxN][2];
char c[maxN][maxN];
signed main(){
// freopen(".inp", "r", stdin);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
memset(dp, 0, sizeof(dp));
memset(c, 0, sizeof(c));
cin >> n >> m;
for1(i, 1, n) for1(j, 1, m) cin >> c[i][j];
for2(i, n, 1) for2(j, m, 1){
string s;
s.clear();
for1(g, j, j + 2) s.pb(c[i][g]);
if(s == "RGW"){
dp[i][j][0] = max(dp[i + 1][j - 1][0], dp[i + 1][j - 1][1]) + 1;
}
s.clear();
for1(g, i, i + 2) s.pb(c[g][j]);
if(s == "RGW"){
dp[i][j][1] = max((j >= 3 ? dp[i + 3][j - 3][0] : 0), dp[i + 1][j - 1][1]) + 1;
}
for1(g, 0, 1){
dp[i][j][g] = max(dp[i][j][g], dp[i + 1][j - 1][g]);
}
}
// cout << dp[2][1][0] << " " << dp[2][1][1] << endl;
int ans = 0;
for1(i, 1, n){
for1(j, 1, m) if(j == m || i == 1) ans += max(dp[i][j][0], dp[i][j][1]);
}
cout << ans << endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |