Submission #1068911

#TimeUsernameProblemLanguageResultExecution timeMemory
1068911epicci23Dango Maker (JOI18_dango_maker)C++17
100 / 100
134 ms124244 KiB
#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,res=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++) res+=ans[i][1];
  for(int j=2;j<=m;j++) res+=ans[n][j];
  cout << res << '\n';
}

int32_t main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tc=1;//cin >> tc;
  while(tc--) _();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...