# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1068905 | epicci23 | Dango Maker (JOI18_dango_maker) | C++17 | 0 ms | 0 KiB |
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"
#define all(v) v.begin() , v.end()
using namespace std;
const int INF = 1e9;
const int N = 3005;
int dp[N][N][2],ans[N][N];
void _(){
int n,m,ans=0;
cin >> n >> m;
vector<string> v;
v.push_back("$");
for(int i=0;i<n;i++){
string s;cin >> s;
s="$"+s;
v.push_back(s);
}
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
bool ok0=0,ok1=0;
if(i+2<=n && v[i][j]=='R' && v[i+1][j]=='G' && v[i+2][j]=='W') ok0=1;
if(j+2<=m && v[i][j]=='R' && v[i][j+1]=='G' && v[i][j+2]=='W') ok1=1;
dp[i][j][0]=dp[i][j][1]=-INF;
if(ok0){
dp[i][j][0]=1;
if(i-1>=1 && j+1<=m) dp[i][j][0]=max(dp[i][j][0],ans[i-1][j+1]+1);
}
else dp[i][j][0]=-INF;
if(ok1){
dp[i][j][1]=1;
if(i-1>=1 && j+1<=m) dp[i][j][1]=max(dp[i][j][1],dp[i-1][j+1][1]+1);
if(i-2>=1 && j+2<=m) dp[i][j][1]=max(dp[i][j][1],dp[i-2][j+2][1]+1);
if(i-3>=1 && j+3<=m) dp[i][j][1]=max(dp[i][j][1],ans[i-3][j+3]+1);
}
else dp[i][j][1]=-INF;
ans[i][j]=max({ans[i-1][j+1],dp[i][j][0],dp[i][j][1]});
}
}
for(int i=1;i<=n;i++) ans+=ans[i][1];
cout << ans << '\n';
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}