This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 3e3+23, lg = 20;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int n, m, ans, dp[2*N][3][3], ok[N][N][2], a[N][N];
bool inGrid(int x, int y) {
if(x>0&&x<=n&&y>0&&y<=m) return 1;
return 0;
}
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
char ch; cin>>ch;
if(ch=='G') a[i][j]=1;
if(ch=='W') a[i][j]=2;
}
}
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
if(a[i][j]==0 && a[i+1][j]==1 && a[i+2][j]==2) ok[i][j][0] = 1;
if(a[i][j]==0 && a[i][j+1]==1 && a[i][j+2]==2) ok[i][j][1] = 1;
}
}
for(int ij=1; ij<=n+m; ij++) {
int cnt = 1;
for(int j,i=1; i<=n&&i<ij; i++) {
j = ij-i;
if(inGrid(i,j)==0) continue;
dp[cnt][2][0] = max({dp[cnt-1][0][0], dp[cnt-1][0][1], dp[cnt-1][0][2]});
dp[cnt][2][1] = max({dp[cnt-1][1][0], dp[cnt-1][1][1], dp[cnt-1][1][2]});
dp[cnt][2][2] = max({dp[cnt-1][2][0], dp[cnt-1][2][1], dp[cnt-1][2][2]});
if(ok[i][j][0] == 1) {
dp[cnt][0][0] = 1+dp[cnt][2][0];
dp[cnt][0][1] = 1+dp[cnt][2][1];
dp[cnt][0][2] = 1+dp[cnt][2][2];
}
if(ok[i][j][1] == 1) {
dp[cnt][1][2] = 1+max(dp[cnt-1][2][1], dp[cnt-1][2][2]);
dp[cnt][1][1] = 1+max(dp[cnt-1][1][1], dp[cnt-1][1][2]);
}
cnt++;
}
int mx = 0;
for(int i=0; i<3; i++) for(int j=0; j<3; j++) mx = max(mx, dp[cnt-1][i][j]);
ans += mx;
for(int l=1; l<cnt; l++) {
for(int i=0; i<3; i++) for(int j=0; j<3; j++) dp[l][i][j] = 0;
}
}
cout<<ans<<endl;
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... |