#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 (a[i][j] == '.') continue;
tr1 = tr2 = true;
dfs(i, j);
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
16 ms |
15960 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
4 |
Incorrect |
9 ms |
10220 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
5876 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
4444 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
2972 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
5980 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
5724 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
5724 KB |
Output isn't correct |
15 |
Incorrect |
16 ms |
16592 KB |
Output isn't correct |
16 |
Incorrect |
20 ms |
15936 KB |
Output isn't correct |
17 |
Incorrect |
16 ms |
15708 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
10332 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
3932 KB |
Output isn't correct |
2 |
Incorrect |
100 ms |
101640 KB |
Output isn't correct |
3 |
Incorrect |
1300 ms |
1034668 KB |
Output isn't correct |
4 |
Incorrect |
236 ms |
242992 KB |
Output isn't correct |
5 |
Incorrect |
591 ms |
582232 KB |
Output isn't correct |
6 |
Incorrect |
1183 ms |
1034388 KB |
Output isn't correct |
7 |
Incorrect |
3 ms |
3672 KB |
Output isn't correct |
8 |
Incorrect |
4 ms |
3932 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
3932 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2256 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
3676 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
1884 KB |
Output isn't correct |
13 |
Incorrect |
103 ms |
101664 KB |
Output isn't correct |
14 |
Incorrect |
57 ms |
58704 KB |
Output isn't correct |
15 |
Incorrect |
63 ms |
65068 KB |
Output isn't correct |
16 |
Incorrect |
40 ms |
41820 KB |
Output isn't correct |
17 |
Incorrect |
258 ms |
262484 KB |
Output isn't correct |
18 |
Incorrect |
262 ms |
259084 KB |
Output isn't correct |
19 |
Incorrect |
246 ms |
242920 KB |
Output isn't correct |
20 |
Incorrect |
214 ms |
222764 KB |
Output isn't correct |
21 |
Incorrect |
629 ms |
602428 KB |
Output isn't correct |
22 |
Incorrect |
599 ms |
581972 KB |
Output isn't correct |
23 |
Incorrect |
520 ms |
500932 KB |
Output isn't correct |
24 |
Incorrect |
611 ms |
587868 KB |
Output isn't correct |
25 |
Incorrect |
1184 ms |
1034640 KB |
Output isn't correct |
26 |
Correct |
832 ms |
791916 KB |
Output is correct |
27 |
Incorrect |
1191 ms |
1034388 KB |
Output isn't correct |
28 |
Incorrect |
1158 ms |
1034160 KB |
Output isn't correct |
29 |
Incorrect |
1255 ms |
1036632 KB |
Output isn't correct |
30 |
Incorrect |
1177 ms |
1014508 KB |
Output isn't correct |
31 |
Incorrect |
782 ms |
663972 KB |
Output isn't correct |
32 |
Incorrect |
1157 ms |
1036296 KB |
Output isn't correct |