#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int h,w;
cin >> h >> w;
vector<string> meadow(h);
for(auto& str : meadow)
cin >> str;
queue<pair<int, int>> qu;
int ans = 0;
const int xoff[4] = {-1, 0, 0, 1};
const int yoff[4] = {0, -1, 1, 0};
for(int y=0; y<h; y++) {
for(int x=0; x<w; x++) {
if(meadow[y][x] == '.')
continue;
bool found_fox = false;
bool found_rabbit = false;
qu.push({y, x});
while(qu.size()) {
auto [ny, nx] = qu.front();
qu.pop();
found_fox |= meadow[ny][nx] == 'F';
found_rabbit |= meadow[ny][nx] == 'R';
meadow[ny][nx] = '.';
for(int cy,cx,k=0; k<4; k++) {
cy = ny + yoff[k];
cx = nx + xoff[k];
if(cy >= 0 && cx >= 0 &&
cy < h && cx < w &&
meadow[cy][cx] != '.')
qu.push({cy, cx});
}
}
ans += found_fox + found_rabbit;
}
}
cout << ans << '\n';
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |