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>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
char s[n+5][m+5];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>s[i][j];
}
}
vector<int>v[n+m+5];
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
int cur=0;
if((i>1&&s[i-1][j]=='R')&&s[i][j]=='G'&&(i<n&&s[i+1][j]=='W')){
cur+=1;
}
if((j>1&&s[i][j-1]=='R')&&s[i][j]=='G'&&(j<m&&s[i][j+1]=='W')){
cur+=2;
}
v[i+j].pb(cur);
}
}
int ans=0;
vector<int>dp(3),dp1(3);
for(int i=2;i<=n+m;i++){
fill(all(dp),0);
for(auto num:v[i]){
for(int j=0;j<3;j++){
dp1[j]=dp[j];
dp[j]=0;
}
dp[0]=max({dp1[0],dp1[1],dp1[2]});
if(num&1) dp[1]=max(dp1[0],dp1[2])+1;
if(num&2) dp[2]=max(dp1[0],dp1[1])+1;
}
ans+=max({dp[0],dp[1],dp[2]});
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |