This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <queue>
using namespace std;
char tab[4000][4000];
int n, m, f, r, ans;
queue<pair<int, int> > fila;
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> tab[i][j];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
{
if (tab[i][j] != '.')
{
f = 0, r = 0;
fila.push(make_pair(i, j));
while (!fila.empty())
{
int a = fila.front().first, b = fila.front().second; fila.pop();
if (a < 0 || b < 0 || a > n - 1 || b > m - 1) continue;
if (tab[a][b] == '.') continue;
else if (tab[a][b] == 'R') r = 1;
else f = 1;
tab[a][b] = '.';
fila.push(make_pair(a + 1, b));
fila.push(make_pair(a - 1, b));
fila.push(make_pair(a, b + 1));
fila.push(make_pair(a, b - 1));
}
ans += f + r;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |