#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ins insert
#define all(x) x.begin(), x.end()
#define F first
#define S second
const int N = 9000100;
char a[3001][3001];
int mt[N], timer, n, m;
int func(int i, int j){
return (i - 1) * m + j;
}
void solve(){
cin>>n>>m;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin>>a[i][j];
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(j + 2 <= m && a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W' && !mt[func(i, j + 2)] && !mt[func(i, j)]){
mt[func(i, j + 2)] = func(i, j);
mt[func(i, j)] = func(i, j + 2);
ans++;
}
}
for(int j = 1; j <= m; j++){
if(i + 2 <= n && a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W' && !mt[func(i + 2, j)] && !mt[func(i, j)]){
mt[func(i + 2, j)] = func(i, j);
mt[func(i, j)] = func(i + 2, j);
ans++;
}
}
}
cout<<ans<<'\n';
}
signed main(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
//cin>>t;
while(t--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |