#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define int long long
#define pi pair<int, int>
#define f first
#define s second
const int N = 4005;
vector<vector<char>> grid(N, vector<char>(N));
vector<vector<bool>> vis(N, vector<bool>(N, 0));
vector<pi> rabbits;
vector<pi> foxes;
vector<pi> moves = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int n, m;
bool ok(int i, int j)
{
return (i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '.' && !vis[i][j]);
}
void bfs(pi pos)
{
queue<pi> q;
q.push({pos.f, pos.s});
vis[pos.f][pos.s] = true;
while (!q.empty())
{
auto p = q.front();
q.pop();
for (auto move : moves)
{
if (ok(p.f + move.f, p.s + move.s))
{
vis[p.f + move.f][p.s + move.s] = true;
q.push({p.f + move.f, p.s + move.s});
}
}
}
}
signed main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> grid[i][j];
if (grid[i][j] == 'R')
{
rabbits.push_back({i, j});
}
else if (grid[i][j] == 'F')
{
foxes.push_back({i, j});
}
}
}
int ans = 0;
for (auto p : rabbits)
{
if (!vis[p.f][p.s])
{
bfs({p.f, p.s});
ans++;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
vis[i][j] = false;
}
}
for (auto p : foxes)
{
if (!vis[p.f][p.s])
{
bfs({p.f, p.s});
ans++;
}
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
32 ms |
22280 KB |
Output isn't correct |
2 |
Incorrect |
10 ms |
18268 KB |
Output isn't correct |
3 |
Incorrect |
14 ms |
18264 KB |
Output isn't correct |
4 |
Incorrect |
25 ms |
21784 KB |
Output isn't correct |
5 |
Incorrect |
16 ms |
18904 KB |
Output isn't correct |
6 |
Incorrect |
11 ms |
18268 KB |
Output isn't correct |
7 |
Incorrect |
11 ms |
18356 KB |
Output isn't correct |
8 |
Incorrect |
11 ms |
18524 KB |
Output isn't correct |
9 |
Incorrect |
11 ms |
18268 KB |
Output isn't correct |
10 |
Incorrect |
15 ms |
19096 KB |
Output isn't correct |
11 |
Incorrect |
14 ms |
19416 KB |
Output isn't correct |
12 |
Incorrect |
19 ms |
20072 KB |
Output isn't correct |
13 |
Incorrect |
16 ms |
18904 KB |
Output isn't correct |
14 |
Incorrect |
18 ms |
19020 KB |
Output isn't correct |
15 |
Incorrect |
31 ms |
21944 KB |
Output isn't correct |
16 |
Incorrect |
34 ms |
22292 KB |
Output isn't correct |
17 |
Incorrect |
30 ms |
20432 KB |
Output isn't correct |
18 |
Incorrect |
24 ms |
21784 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
18776 KB |
Output isn't correct |
2 |
Incorrect |
111 ms |
34984 KB |
Output isn't correct |
3 |
Incorrect |
762 ms |
89712 KB |
Output isn't correct |
4 |
Incorrect |
201 ms |
34716 KB |
Output isn't correct |
5 |
Incorrect |
554 ms |
124852 KB |
Output isn't correct |
6 |
Incorrect |
1959 ms |
406092 KB |
Output isn't correct |
7 |
Incorrect |
15 ms |
18780 KB |
Output isn't correct |
8 |
Incorrect |
14 ms |
18776 KB |
Output isn't correct |
9 |
Incorrect |
15 ms |
19036 KB |
Output isn't correct |
10 |
Incorrect |
13 ms |
18588 KB |
Output isn't correct |
11 |
Incorrect |
13 ms |
18520 KB |
Output isn't correct |
12 |
Incorrect |
12 ms |
18524 KB |
Output isn't correct |
13 |
Incorrect |
110 ms |
34556 KB |
Output isn't correct |
14 |
Incorrect |
67 ms |
27320 KB |
Output isn't correct |
15 |
Incorrect |
66 ms |
27152 KB |
Output isn't correct |
16 |
Incorrect |
57 ms |
26812 KB |
Output isn't correct |
17 |
Incorrect |
255 ms |
51072 KB |
Output isn't correct |
18 |
Incorrect |
242 ms |
48276 KB |
Output isn't correct |
19 |
Incorrect |
203 ms |
36000 KB |
Output isn't correct |
20 |
Incorrect |
176 ms |
35828 KB |
Output isn't correct |
21 |
Incorrect |
483 ms |
76848 KB |
Output isn't correct |
22 |
Incorrect |
546 ms |
127032 KB |
Output isn't correct |
23 |
Incorrect |
480 ms |
79216 KB |
Output isn't correct |
24 |
Incorrect |
486 ms |
75320 KB |
Output isn't correct |
25 |
Incorrect |
998 ms |
129980 KB |
Output isn't correct |
26 |
Correct |
933 ms |
289164 KB |
Output is correct |
27 |
Incorrect |
1718 ms |
361132 KB |
Output isn't correct |
28 |
Incorrect |
1955 ms |
405960 KB |
Output isn't correct |
29 |
Incorrect |
1731 ms |
281348 KB |
Output isn't correct |
30 |
Incorrect |
1805 ms |
359060 KB |
Output isn't correct |
31 |
Incorrect |
1188 ms |
224244 KB |
Output isn't correct |
32 |
Incorrect |
1596 ms |
297116 KB |
Output isn't correct |