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 <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<string> mat(n);
string res;
for (string& s : mat) {
cin >> s;
res += s;
}
vector vis(n, vector(m, 0));
auto dfs = [&](auto &dfs, int i, int j)-> void {
if (i < 0 || i >= n || j < 0 || j >= m) return;
if (vis[i][j]) return;
if (mat[i][j] != mat[0][0]) return;
vis[i][j] = 1;
dfs(dfs, i+1, j);
dfs(dfs, i-1, j);
dfs(dfs, i, j+1);
dfs(dfs, i, j-1);
};
int r = res.find('R') != string::npos;
int f = res.find('F') != string::npos;
if (f&&r) {
dfs(dfs, 0, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!vis[i][j] && mat[i][j] == mat[0][0]) { f = 2; break; }
}
}
}
cout << r+f<< '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |