이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n, m, ans;
bool tr1, tr2;
vector<string> a;
vector<vector<bool>> vis;
bool chk(int x, int y) {
return 0 <= min(x, y) && x < n && y < m && !vis[x][y];
}
void dfs(int x, int y) {
if (vis[x][y]) return;
vis[x][y] = true;
if (a[x][y] == 'R') {
ans += tr1; tr1 = false;
}
else {
ans += tr2; tr2 = false;
}
if (chk(x - 1, y)) dfs(x - 1, y);
if (chk(x + 1, y)) dfs(x + 1, y);
if (chk(x, y - 1)) dfs(x, y - 1);
if (chk(x, y + 1)) dfs(x, y + 1);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
a.assign(n, "");
for (auto &i : a) cin >> i;
vis.assign(n, vector<bool>(m, false));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (!chk(i, j)) continue;
tr1 = tr2 = true;
dfs(i, j);
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |