#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
template<class A, class B>
bool chmin(A &a, const B &b) {
return a > b ? (a = b) == b : false;
} template<class A, class B>
bool chmax(A &a, const B &b) {
return a < b ? (a = b) == b : false;
}
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m; cin >> n >> m;
vector<string> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
}
vector<vector<bool>> vis(n, vector<bool> (m, false));
int f = 0, r = 0;
auto in = [&](int i, int j) {
return i >= 0 && i < n && j >= 0 && j < m;
};
function<void(int, int)> dfs = [&](int i, int j) {
vis[i][j] = true;
if (s[i][j] == 'R') r = 1;
if (s[i][j] == 'F') f = 1;
for (int k = 0; k < 4; ++k) {
int x = i + dx[k];
int y = j + dy[k];
if (in(x, y) && !vis[x][y] && s[x][y] != '.') {
dfs(x, y);
}
}
};
int res = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (!vis[i][j] && s[i][j] != '.') {
dfs(i, j);
res += f + r;
f = r = 0;
}
}
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |