#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i= 0; i<(n); i++)
#define reps(i,s, n) for(int i= (s); i<(n); i++)
#define each(a, x) for (auto &a : x)
#define vv(T) vector<T>
#define endl '\n'
#define sz(x) (int)x.size()
#define ll long long
#define all(c) begin(c), end(c)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define wr cout<<
#define wre wr endl;
#define wrut(a) {each(i,(a))wr i; wre}
#define wrot(a,b,c) {wre wr a<<" "<<b<<" "<<c; wre}
// #define int ll
// const int mod=1e9+7;
// const int maxn=(1e3)*3+7;
// int dp[maxn][maxn];
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
char c;
vv(vv(int)) a(n+2,vv(int)(m+2,0));
vv(vv(bool)) vis(n+2,vv(bool)(m+2,1));
rep(i,n){
rep(j,m){
cin>>c;
if(c=='R'){
a[i+1][j+1]=1;
vis[i+1][j+1]=0;
} else if(c=='F'){
a[i+1][j+1]=2;
vis[i+1][j+1]=0;
}
}
}
int s=0;
bool r=0,f=0;
queue<pair<int,int>> q;
rep(i,n){
rep(j,m){
if(!vis[i+1][j+1]){
r=0;f=0;
q.push(mp(i+1,j+1));
vis[i+1][j+1]=1;
while(!q.empty()){
pair<int,int> p=q.front();
q.pop();
if(a[p.fi][p.se]==1)r=1;
if(a[p.fi][p.se]==2)f=2;
if(!vis[p.fi-1][p.se]){
q.push(mp(p.fi-1,p.se));
vis[p.fi-1][p.se]=1;
}
if(!vis[p.fi+1][p.se]){
q.push(mp(p.fi+1,p.se));
vis[p.fi+1][p.se]=1;
}
if(!vis[p.fi][p.se+1]){
q.push(mp(p.fi,p.se+1));
vis[p.fi][p.se+1]=1;
}
if(!vis[p.fi][p.se-1]){
q.push(mp(p.fi,p.se-1));
vis[p.fi][p.se-1]=1;
}
}
if(r)s++;
if(f)s++;
}
}
}
wr s;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |