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[4002][4002];
int n, m, f, r, ans, passou[4002][4002], passou2[4002][4002];
queue<pair<int, int> > fila;
void bfs(int a, int b)
{
fila.push(make_pair(a, b));
while (!fila.empty())
{
int a = fila.front().first, b = fila.front().second; fila.pop();
if (a < 1 || b < 1 || a > n || b > m) continue;
if (tab[a][b] == '.' || passou[a][b]) continue;
r += (tab[a][b] == 'R'), f += (tab[a][b] == 'F');
passou[a][b] = 1;
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));
}
}
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> tab[i][j];
bfs(1, 1);
r = min(r, 1), f = min(f, 1);
cout << r + f << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |