#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 4007;
const pair < int, int > D[4] = {
make_pair(1,0),
make_pair(-1,0),
make_pair(0,1),
make_pair(0,-1)
};
int n,m;
char a[N][N];
bool used[N][N];
int ans;
void clear_used() {
int i,j;
for(i=1;i<=n;i++) {
for(j=1;j<=m;j++) {
used[i][j]=false;
}
}
}
void dfs(int r, int c, char ch) {
a[r][c]='#';
used[r][c]=true;
int i,p,t;
for(i=0;i<4;i++) {
p=r+D[i].first;
t=c+D[i].second;
if(p>=1 && p<=n && t>=1 && t<=m) if(!used[p][t]) if(a[p][t]==ch || a[p][t]=='#') dfs(p,t,ch);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int i,j;
scanf("%d %d", &n, &m);
for(i=1;i<=n;i++) {
scanf("%s", a[i]+1);
}
for(i=1;i<=n;i++) {
for(j=1;j<=m;j++) {
if(a[i][j]!='#' && a[i][j]!='.') {
clear_used();
dfs(i,j,a[i][j]);
++ans;
}
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
tracks.cpp: In function 'int main()':
tracks.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
tracks.cpp:50:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", a[i]+1);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
14072 KB |
Output is correct |
2 |
Incorrect |
2 ms |
14072 KB |
Output isn't correct |
3 |
Incorrect |
4 ms |
14072 KB |
Output isn't correct |
4 |
Correct |
25 ms |
14072 KB |
Output is correct |
5 |
Incorrect |
89 ms |
14072 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
14072 KB |
Output isn't correct |
7 |
Incorrect |
4 ms |
14072 KB |
Output isn't correct |
8 |
Correct |
3 ms |
14072 KB |
Output is correct |
9 |
Incorrect |
5 ms |
14072 KB |
Output isn't correct |
10 |
Incorrect |
54 ms |
14072 KB |
Output isn't correct |
11 |
Correct |
7 ms |
14072 KB |
Output is correct |
12 |
Correct |
54 ms |
14072 KB |
Output is correct |
13 |
Incorrect |
62 ms |
14072 KB |
Output isn't correct |
14 |
Incorrect |
63 ms |
14072 KB |
Output isn't correct |
15 |
Correct |
345 ms |
14072 KB |
Output is correct |
16 |
Correct |
243 ms |
15272 KB |
Output is correct |
17 |
Incorrect |
425 ms |
15272 KB |
Output isn't correct |
18 |
Correct |
23 ms |
15272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
742 ms |
33088 KB |
Output isn't correct |
2 |
Execution timed out |
2065 ms |
33088 KB |
Time limit exceeded |
3 |
Execution timed out |
2079 ms |
39128 KB |
Time limit exceeded |
4 |
Execution timed out |
2079 ms |
39128 KB |
Time limit exceeded |
5 |
Execution timed out |
2084 ms |
39672 KB |
Time limit exceeded |
6 |
Execution timed out |
2084 ms |
344192 KB |
Time limit exceeded |
7 |
Incorrect |
1207 ms |
344192 KB |
Output isn't correct |
8 |
Incorrect |
795 ms |
344192 KB |
Output isn't correct |
9 |
Incorrect |
105 ms |
344192 KB |
Output isn't correct |
10 |
Incorrect |
257 ms |
344192 KB |
Output isn't correct |
11 |
Incorrect |
770 ms |
344192 KB |
Output isn't correct |
12 |
Incorrect |
95 ms |
344192 KB |
Output isn't correct |
13 |
Execution timed out |
2053 ms |
344192 KB |
Time limit exceeded |
14 |
Execution timed out |
2061 ms |
344192 KB |
Time limit exceeded |
15 |
Execution timed out |
2083 ms |
344192 KB |
Time limit exceeded |
16 |
Execution timed out |
2076 ms |
344192 KB |
Time limit exceeded |
17 |
Execution timed out |
2050 ms |
344192 KB |
Time limit exceeded |
18 |
Execution timed out |
2050 ms |
344192 KB |
Time limit exceeded |
19 |
Execution timed out |
2061 ms |
344192 KB |
Time limit exceeded |
20 |
Execution timed out |
2074 ms |
344192 KB |
Time limit exceeded |
21 |
Execution timed out |
2063 ms |
344192 KB |
Time limit exceeded |
22 |
Execution timed out |
2074 ms |
344192 KB |
Time limit exceeded |
23 |
Execution timed out |
2058 ms |
344192 KB |
Time limit exceeded |
24 |
Execution timed out |
2058 ms |
344192 KB |
Time limit exceeded |
25 |
Execution timed out |
2074 ms |
344192 KB |
Time limit exceeded |
26 |
Correct |
1200 ms |
687528 KB |
Output is correct |
27 |
Execution timed out |
2082 ms |
687528 KB |
Time limit exceeded |
28 |
Execution timed out |
2078 ms |
687528 KB |
Time limit exceeded |
29 |
Execution timed out |
2091 ms |
687528 KB |
Time limit exceeded |
30 |
Execution timed out |
2082 ms |
687528 KB |
Time limit exceeded |
31 |
Execution timed out |
2071 ms |
687528 KB |
Time limit exceeded |
32 |
Execution timed out |
2084 ms |
687528 KB |
Time limit exceeded |