#include<bits/stdc++.h>
using namespace std;
const int N=4e3+1;
char a[N][N];
int xx[4]={0,0,1,-1};
int yy[4]={1,-1,0,0};
bool vis[N][N];
void dfs(int py, int px, char c){
a[py][px]='?';
vis[py][px]=1;
for(int i=0;i<4;i++){
if((a[py+yy[i]][px+xx[i]]=='?' or a[py+yy[i]][px+xx[i]]==c) and vis[py+yy[i]][px+xx[i]]==0){
dfs(py+yy[i],px+xx[i],c);
}
}
}
signed main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]=='F' or a[i][j]=='R'){
for(int x=1;x<=n;x++){
for(int y=1;y<=m;y++)vis[x][y]=0;
}
dfs(i,j,a[i][j]);
cnt++;
i=1;
j=1;
}
}
}
cout<<cnt;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
131 ms |
22448 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
4 |
Correct |
19 ms |
15964 KB |
Output is correct |
5 |
Incorrect |
38 ms |
7360 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
4700 KB |
Output isn't correct |
8 |
Correct |
1 ms |
4956 KB |
Output is correct |
9 |
Incorrect |
2 ms |
4700 KB |
Output isn't correct |
10 |
Incorrect |
27 ms |
7064 KB |
Output isn't correct |
11 |
Correct |
5 ms |
7512 KB |
Output is correct |
12 |
Correct |
46 ms |
11704 KB |
Output is correct |
13 |
Incorrect |
40 ms |
7256 KB |
Output isn't correct |
14 |
Incorrect |
38 ms |
7260 KB |
Output isn't correct |
15 |
Correct |
209 ms |
9192 KB |
Output is correct |
16 |
Correct |
139 ms |
22352 KB |
Output is correct |
17 |
Incorrect |
266 ms |
10488 KB |
Output isn't correct |
18 |
Correct |
20 ms |
15964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
532 ms |
32456 KB |
Output isn't correct |
2 |
Execution timed out |
2088 ms |
19388 KB |
Time limit exceeded |
3 |
Execution timed out |
2055 ms |
40512 KB |
Time limit exceeded |
4 |
Execution timed out |
2065 ms |
31312 KB |
Time limit exceeded |
5 |
Execution timed out |
2041 ms |
30288 KB |
Time limit exceeded |
6 |
Execution timed out |
2097 ms |
590844 KB |
Time limit exceeded |
7 |
Incorrect |
792 ms |
32888 KB |
Output isn't correct |
8 |
Incorrect |
531 ms |
32156 KB |
Output isn't correct |
9 |
Incorrect |
56 ms |
3600 KB |
Output isn't correct |
10 |
Incorrect |
177 ms |
3160 KB |
Output isn't correct |
11 |
Incorrect |
416 ms |
32116 KB |
Output isn't correct |
12 |
Incorrect |
78 ms |
5456 KB |
Output isn't correct |
13 |
Execution timed out |
2066 ms |
20292 KB |
Time limit exceeded |
14 |
Execution timed out |
2024 ms |
15528 KB |
Time limit exceeded |
15 |
Execution timed out |
2032 ms |
11860 KB |
Time limit exceeded |
16 |
Execution timed out |
2037 ms |
10784 KB |
Time limit exceeded |
17 |
Execution timed out |
2050 ms |
26064 KB |
Time limit exceeded |
18 |
Execution timed out |
2035 ms |
23080 KB |
Time limit exceeded |
19 |
Execution timed out |
2045 ms |
35212 KB |
Time limit exceeded |
20 |
Execution timed out |
2050 ms |
22184 KB |
Time limit exceeded |
21 |
Execution timed out |
2045 ms |
37656 KB |
Time limit exceeded |
22 |
Execution timed out |
2066 ms |
36524 KB |
Time limit exceeded |
23 |
Execution timed out |
2032 ms |
34576 KB |
Time limit exceeded |
24 |
Execution timed out |
2035 ms |
37132 KB |
Time limit exceeded |
25 |
Execution timed out |
2020 ms |
47780 KB |
Time limit exceeded |
26 |
Correct |
1869 ms |
990460 KB |
Output is correct |
27 |
Execution timed out |
2068 ms |
740008 KB |
Time limit exceeded |
28 |
Execution timed out |
2067 ms |
782868 KB |
Time limit exceeded |
29 |
Execution timed out |
2096 ms |
862168 KB |
Time limit exceeded |
30 |
Execution timed out |
2118 ms |
935324 KB |
Time limit exceeded |
31 |
Execution timed out |
2049 ms |
160796 KB |
Time limit exceeded |
32 |
Execution timed out |
2040 ms |
623536 KB |
Time limit exceeded |