#include <bits/stdc++.h>
using namespace std;
/*
#include<Luck>
Compete against Yourself.
Author - swayam_wish
*/
#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define pis pair<int, string>
#define db double
int mod = 1e9+7;
ll gcd(ll a, ll b){
if(min(a,b) == 0){
return max(a,b);
}
if((a%b) == 0){
return b;
}
return gcd(b,a%b);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
t = 1;
while(t--){
int h , w;
cin >> h >> w;
vector<vector<char>> grid(h,vector<char>(w));
for(int i = 0; i<h; i++){
for(int j = 0; j<w; j++){
cin >> grid[i][j];
}
}
vector<int> ans(2,0);
queue<pii> q;
q.push({0,0});
vector<vector<int>> vis(h,vector<int>(w,0));
int delx[] = {0,0,-1,1};
int dely[] = {1,-1,0,0};
while(!q.empty()){
auto it = q.front();
q.pop();
int x = it.first;
int y = it.second;
for(int i = 0 ; i<4; i++){
int cx = x + delx[i];
int cy = y + dely[i];
if(cx<0 || cy<0 || cx==h || cy==w || vis[cx][cy]!=0 || grid[cx][cy]!=grid[x][y]){
continue;
}
q.push({cx,cy});
vis[cx][cy] = 1;
}
}
for(int i = 0; i<h; i++){
for(int j = 0; j<w; j++){
if(vis[i][j] == 0){
if(grid[i][j] == 'F'){
ans[0] = 1;
}
else if(grid[i][j] == 'R'){
ans[1] = 1;
}
}
}
}
cout<<(ans[0]+ans[1]+1)<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |