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<iostream>
#include<stdio.h>
#include<math.h>
#include<map>
#include<string>
#include<algorithm>
#include<vector>
#include<string.h>
#include<utility>
#include<set>
#include<cmath>
#include<queue>
#include<deque>
#include<functional>
#include<stack>
#include<limits.h>
#include<iomanip>
#include<unordered_map>
#include<numeric>
#include<tuple>
using namespace std;
#define MOD 1000000007
#define int long long
#define endl '\n'
void solve(){
int n,m; cin>>n>>m;
vector<vector<char> > a(n+1,vector<char>(m+1));
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
cin>>a[i][j];
}
}
vector<vector<int> > dp(n+1,vector<int>(m+1));
for(int i=1; i<=n; i++){
dp[i][0]=dp[i-1][m];
for(int j=1; j<=m; j++){
dp[i][j]=dp[i][j-1];
if(a[i][j]=='W'){
if(j>=3){
if(a[i][j-1]=='G'&&a[i][j-2]=='R'){
dp[i][j]=max(dp[i][j],dp[i][j-3]+1);
}
}
if(i>=3){
if(a[i-1][j]=='G'&&a[i-2][j]=='R'){
int sum=0;
if(j<=m-2&&a[i-2][j+1]=='G'&&a[i-2][j+2]=='W') sum++;
if(j>1&&j<m&&a[i-1][j-1]=='R'&&a[i-1][j+1]=='W') sum++;
dp[i][j]=max(dp[i][j],dp[i][j-1]-sum+1);
}
}
}
}
}
cout<<dp[n][m];
}
signed main(){
// freopen("248.in", "r", stdin);
// freopen("248.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t=1;
// cin>>t;
while(t--){
solve();
cout<<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... |