#include <bits/stdc++.h>
#define int long long
using namespace std;
char c[3000][3000];
int n,m;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>n>>m;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
cin>>c[i][j];
int ans=0;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(c[i][j]!='R') continue;
if(j+2<m && c[i][j+1]=='G' && c[i][j+2]=='W'){
ans++;
c[i][j]=c[i][j+1]=c[i][j+2]='A';
continue;
}
if(j-2>=0 && c[i][j-1]=='G' && c[i][j-2]=='W'){
ans++;
c[i][j]=c[i][j-1]=c[i][j-2]='A';
continue;
}
if(i+2<n && c[i+1][j]=='G' && c[i+2][j]=='W'){
ans++;
c[i][j]=c[i+1][j]=c[i+2][j]='A';
continue;
}
if(i-2>=0 && c[i-1][j]=='G' && c[i-2][j]=='W'){
ans++;
c[i][j]=c[i-1][j]=c[i-2][j]='A';
continue;
}
}
}
cout<<ans;
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... |