#include <bits/stdc++.h>
using namespace std;
const int mxN = 4000;
int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};
char G[mxN][mxN];
bool vis[mxN][mxN];
int N, M;
bool valid(int i, int j) {
return 0 <= i && i < N && 0 <= j && j < M;
}
void dfs(int i, int j, bool which) {
if (vis[i][j]) return;
vis[i][j] = 1;
for (int d = 0; d < 4; ++d)
if (valid(i + di[d], j + dj[d]) && (G[i + di[d]][j + dj[d]] == 'R') == which)
dfs(i + di[d], j + dj[d], which);
}
void solve() {
cin >> N >> M;
for (int i = 0; i < N; ++i)
for (int j = 0; j < M; ++j)
cin >> G[i][j];
bool dis[2] = {};
dfs(0, 0, G[0][0] == 'R');
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
if (G[i][j] == '.' || vis[i][j]) continue;
bool which = (G[i][j] == 'R');
dis[which] = 1;
dfs(i, j, which);
}
}
cout << 1 + dis[0] + dis[1] << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
4424 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
444 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
708 KB |
Output isn't correct |
4 |
Incorrect |
10 ms |
4948 KB |
Output isn't correct |
5 |
Incorrect |
5 ms |
4556 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
712 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
716 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
1228 KB |
Output isn't correct |
10 |
Incorrect |
4 ms |
2892 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
2124 KB |
Output isn't correct |
12 |
Incorrect |
5 ms |
2636 KB |
Output isn't correct |
13 |
Incorrect |
5 ms |
4556 KB |
Output isn't correct |
14 |
Incorrect |
5 ms |
4676 KB |
Output isn't correct |
15 |
Incorrect |
13 ms |
6220 KB |
Output isn't correct |
16 |
Incorrect |
16 ms |
4476 KB |
Output isn't correct |
17 |
Incorrect |
17 ms |
8100 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
4888 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
31236 KB |
Output isn't correct |
2 |
Incorrect |
74 ms |
28800 KB |
Output isn't correct |
3 |
Incorrect |
812 ms |
483044 KB |
Output isn't correct |
4 |
Incorrect |
206 ms |
125240 KB |
Output isn't correct |
5 |
Incorrect |
439 ms |
296696 KB |
Output isn't correct |
6 |
Incorrect |
610 ms |
78668 KB |
Output isn't correct |
7 |
Incorrect |
17 ms |
32716 KB |
Output isn't correct |
8 |
Incorrect |
16 ms |
31320 KB |
Output isn't correct |
9 |
Incorrect |
4 ms |
1740 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
1228 KB |
Output isn't correct |
11 |
Incorrect |
21 ms |
32196 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
2124 KB |
Output isn't correct |
13 |
Incorrect |
74 ms |
28808 KB |
Output isn't correct |
14 |
Incorrect |
47 ms |
27716 KB |
Output isn't correct |
15 |
Incorrect |
57 ms |
36664 KB |
Output isn't correct |
16 |
Incorrect |
34 ms |
9028 KB |
Output isn't correct |
17 |
Incorrect |
183 ms |
62532 KB |
Output isn't correct |
18 |
Incorrect |
230 ms |
135628 KB |
Output isn't correct |
19 |
Incorrect |
186 ms |
125232 KB |
Output isn't correct |
20 |
Incorrect |
152 ms |
65540 KB |
Output isn't correct |
21 |
Incorrect |
453 ms |
286760 KB |
Output isn't correct |
22 |
Incorrect |
432 ms |
296792 KB |
Output isn't correct |
23 |
Incorrect |
385 ms |
194748 KB |
Output isn't correct |
24 |
Incorrect |
470 ms |
312404 KB |
Output isn't correct |
25 |
Incorrect |
947 ms |
511076 KB |
Output isn't correct |
26 |
Correct |
1139 ms |
806796 KB |
Output is correct |
27 |
Incorrect |
715 ms |
248408 KB |
Output isn't correct |
28 |
Incorrect |
648 ms |
78788 KB |
Output isn't correct |
29 |
Incorrect |
634 ms |
73352 KB |
Output isn't correct |
30 |
Incorrect |
631 ms |
120116 KB |
Output isn't correct |
31 |
Incorrect |
533 ms |
35940 KB |
Output isn't correct |
32 |
Incorrect |
727 ms |
261060 KB |
Output isn't correct |