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("O2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma")
//*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int ,int > pii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 3020;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
int n , m;
string s[maxn];
int dp[maxn][3];
inline int solve(int i , int j){
dp[j][0] = dp[j][1] = dp[j][2] = 0;
int ans = 0;
while(i > -1 and j < m){
dp[j+1][0] = dp[j + 1][1] = dp[j+1][2] = 0;
if(s[i][j] == 'G' and j > 0 and s[i][j - 1] == 'R' and j + 1 < m and s[i][j+1]=='W')
dp[j][1]++;
if(s[i][j] == 'G' and i > 0 and s[i-1][j] == 'R' and i + 1 < n and s[i+1][j]=='W')
dp[j][2]++;
ans = max({ans , dp[j][0] , dp[j][1] , dp[j][2]});
dp[j+1][0] = max({dp[j][0] , dp[j][1] , dp[j][2]});
dp[j+1][1] = max({dp[j][0] , dp[j][1]});
dp[j+1][2] = max({dp[j][0] , dp[j][2]});
i-- , j++;
}
return(ans);
}
int32_t main(){
migmig;
cin >> n >> m;
for(int i = 0 ; i < n ; i ++)
cin >> s[i];
int ans = 0;
for(int i = 0 ; i < m ; i ++)
ans += solve(n-1 , i);
for(int i = 0 ; i < n-1 ; i ++)
ans += solve(i , 0);
cout << ans;
return(0);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |