#include<bits/stdc++.h>
using namespace std;
const int MXN = 4000, INF = 1e9 + 5;
const int MOD = 1e9 + 7;
int n, m;
char arr[MXN][MXN];
bool vis[MXN][MXN];
char now;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
void dfs(int x, int y){
if(x < 0 || x >= n || y < 0 || y >= m || vis[x][y] || arr[x][y] != now) return;
vis[x][y] = 1;
for(int i = 0; i < 4; i++){
dfs(x + dx[i], y + dy[i]);
}
}
void solve(){
cin >> n >> m;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin >> arr[i][j];
}
}
now = 'R';
int cnt1 = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(!vis[i][j] && arr[i][j] == 'R') cnt1++, dfs(i, j);
}
}
now = 'F';
int cnt2 = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(!vis[i][j] && arr[i][j] == 'F') cnt2++, dfs(i, j);
}
}
cout << min(cnt1, cnt2) + 1 << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(0);
cerr.tie(0);
// freopen("filename.in", "r", stdin);
// freopen("filename.out", "w", stdout);
int TC = 1;
// cin >> TC;
while(TC--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
6492 KB |
Output isn't correct |
2 |
Incorrect |
0 ms |
2396 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
4 |
Incorrect |
6 ms |
6864 KB |
Output isn't correct |
5 |
Incorrect |
3 ms |
5464 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
2908 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
3420 KB |
Output isn't correct |
12 |
Incorrect |
4 ms |
5588 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
5468 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
5724 KB |
Output isn't correct |
15 |
Incorrect |
9 ms |
6492 KB |
Output isn't correct |
16 |
Incorrect |
10 ms |
6464 KB |
Output isn't correct |
17 |
Incorrect |
7 ms |
6236 KB |
Output isn't correct |
18 |
Incorrect |
6 ms |
7004 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
31580 KB |
Output isn't correct |
2 |
Incorrect |
33 ms |
11636 KB |
Output isn't correct |
3 |
Incorrect |
234 ms |
32084 KB |
Output isn't correct |
4 |
Incorrect |
53 ms |
18000 KB |
Output isn't correct |
5 |
Incorrect |
144 ms |
26580 KB |
Output isn't correct |
6 |
Incorrect |
458 ms |
52912 KB |
Output isn't correct |
7 |
Incorrect |
8 ms |
31832 KB |
Output isn't correct |
8 |
Incorrect |
8 ms |
31580 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
2652 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
11 |
Incorrect |
8 ms |
31580 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
2908 KB |
Output isn't correct |
13 |
Incorrect |
34 ms |
11612 KB |
Output isn't correct |
14 |
Incorrect |
19 ms |
10076 KB |
Output isn't correct |
15 |
Incorrect |
18 ms |
10588 KB |
Output isn't correct |
16 |
Incorrect |
16 ms |
6228 KB |
Output isn't correct |
17 |
Incorrect |
83 ms |
18776 KB |
Output isn't correct |
18 |
Incorrect |
72 ms |
18724 KB |
Output isn't correct |
19 |
Incorrect |
55 ms |
18004 KB |
Output isn't correct |
20 |
Incorrect |
56 ms |
15704 KB |
Output isn't correct |
21 |
Incorrect |
141 ms |
27220 KB |
Output isn't correct |
22 |
Incorrect |
154 ms |
26708 KB |
Output isn't correct |
23 |
Incorrect |
152 ms |
22608 KB |
Output isn't correct |
24 |
Incorrect |
156 ms |
27220 KB |
Output isn't correct |
25 |
Incorrect |
269 ms |
31944 KB |
Output isn't correct |
26 |
Correct |
614 ms |
606068 KB |
Output is correct |
27 |
Incorrect |
412 ms |
163788 KB |
Output isn't correct |
28 |
Incorrect |
463 ms |
52680 KB |
Output isn't correct |
29 |
Incorrect |
432 ms |
48212 KB |
Output isn't correct |
30 |
Incorrect |
435 ms |
97620 KB |
Output isn't correct |
31 |
Incorrect |
380 ms |
27608 KB |
Output isn't correct |
32 |
Incorrect |
445 ms |
234444 KB |
Output isn't correct |