//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
const int N = 1e6, NN=26;
const int mod=1e9+7;
//int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); }
//int lcm(int a, int b) { return a / gcd(a, b) * b; }
//int binpow(int a,int b){if(!b)return 1; if(b&1)return a*binpow(a,b-1)%mod; int x=binpow(a,b/2); return x*x%mod;}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
char a[n+1][m+1];
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-2;j++){
if(a[i][j]=='R' && a[i][j+1]=='G' && a[i][j+2]=='W'){
ans++;
a[i][j] = a[i][j+1] = a[i][j+2] = '0';
}
}
}
for(int j=1;j<=m;j++){
for(int i=1;i<=n-2;i++){
if(a[i][j]!='R') continue;
int pos=0, pos2=0;
bool b2=0, b3=0;
int ii=i+1;
while(ii<=n && b3==0){
if(b2==0){
if(a[ii][j]=='G'){
b2=1;
pos=ii;
}
}
else{
if(a[ii][j]=='W'){
b3=1;
pos2=ii;
}
}
ii++;
}
if(b3==1){
ans++;
a[i][j] = a[pos][j] = a[pos2][j] = '0';
}
}
}
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... |