#include<bits/stdc++.h>
using namespace std;
int h, w, ans = 0;
vector<vector<char>> v;
vector<vector<bool>> visited(h, vector<bool> (w, 0));
void dfs(vector<vector<char>> &v, int i, int j, char k) {
if(i < 0 or j < 0 or i >= h or j >=w or v[i][j] == '.' or (v[i][j] != '#' and v[i][j] != k) or visited[i][j])return;
else {
if(v[i][j]!='#')
v[i][j] = '#';
else {
v[i][j] = '.';
}
visited[i][j] = true;
dfs(v, i+1, j, k);
dfs(v, i-1, j, k);
dfs(v, i, j+1, k);
dfs(v, i, j-1, k);
}
}
int main () {
cin >> h >> w;
v.resize(h, vector<char> (w));
for(int i = 0;i<h;i++) {
for(int j = 0;j<w;j++) {
cin >> v[i][j];
}
}
for(int i = 0;i<h;i++) {
for(int j = 0;j<w;j++) {
if(v[i][j] != '#' and v[i][j] != '.') {
visited.assign(h, vector<bool> (w, 0));
dfs(v, i, j, v[i][j]);
ans++;
}
}
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
207 ms |
1052 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
292 KB |
Output isn't correct |
4 |
Incorrect |
34 ms |
2220 KB |
Output isn't correct |
5 |
Incorrect |
212 ms |
500 KB |
Output isn't correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
9 |
Incorrect |
7 ms |
324 KB |
Output isn't correct |
10 |
Incorrect |
33 ms |
420 KB |
Output isn't correct |
11 |
Incorrect |
7 ms |
1228 KB |
Output isn't correct |
12 |
Incorrect |
66 ms |
588 KB |
Output isn't correct |
13 |
Incorrect |
202 ms |
500 KB |
Output isn't correct |
14 |
Incorrect |
182 ms |
496 KB |
Output isn't correct |
15 |
Incorrect |
1146 ms |
984 KB |
Output isn't correct |
16 |
Incorrect |
225 ms |
1056 KB |
Output isn't correct |
17 |
Incorrect |
1302 ms |
908 KB |
Output isn't correct |
18 |
Incorrect |
34 ms |
2128 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
767 ms |
988 KB |
Output isn't correct |
2 |
Execution timed out |
2058 ms |
3372 KB |
Time limit exceeded |
3 |
Execution timed out |
2083 ms |
19788 KB |
Time limit exceeded |
4 |
Execution timed out |
2071 ms |
5916 KB |
Time limit exceeded |
5 |
Execution timed out |
2091 ms |
11728 KB |
Time limit exceeded |
6 |
Execution timed out |
2097 ms |
127064 KB |
Time limit exceeded |
7 |
Incorrect |
587 ms |
1016 KB |
Output isn't correct |
8 |
Incorrect |
747 ms |
996 KB |
Output isn't correct |
9 |
Incorrect |
17 ms |
716 KB |
Output isn't correct |
10 |
Incorrect |
6 ms |
460 KB |
Output isn't correct |
11 |
Incorrect |
333 ms |
972 KB |
Output isn't correct |
12 |
Incorrect |
144 ms |
336 KB |
Output isn't correct |
13 |
Execution timed out |
2077 ms |
3364 KB |
Time limit exceeded |
14 |
Execution timed out |
2091 ms |
2372 KB |
Time limit exceeded |
15 |
Execution timed out |
2061 ms |
2500 KB |
Time limit exceeded |
16 |
Incorrect |
427 ms |
1988 KB |
Output isn't correct |
17 |
Execution timed out |
2074 ms |
6476 KB |
Time limit exceeded |
18 |
Execution timed out |
2096 ms |
6184 KB |
Time limit exceeded |
19 |
Execution timed out |
2053 ms |
5904 KB |
Time limit exceeded |
20 |
Execution timed out |
2060 ms |
5572 KB |
Time limit exceeded |
21 |
Execution timed out |
2058 ms |
12252 KB |
Time limit exceeded |
22 |
Execution timed out |
2093 ms |
11796 KB |
Time limit exceeded |
23 |
Execution timed out |
2087 ms |
10532 KB |
Time limit exceeded |
24 |
Execution timed out |
2095 ms |
11956 KB |
Time limit exceeded |
25 |
Execution timed out |
2066 ms |
19668 KB |
Time limit exceeded |
26 |
Correct |
1694 ms |
589452 KB |
Output is correct |
27 |
Execution timed out |
2092 ms |
209768 KB |
Time limit exceeded |
28 |
Execution timed out |
2106 ms |
125920 KB |
Time limit exceeded |
29 |
Execution timed out |
2100 ms |
129416 KB |
Time limit exceeded |
30 |
Execution timed out |
2106 ms |
176144 KB |
Time limit exceeded |
31 |
Execution timed out |
2089 ms |
13364 KB |
Time limit exceeded |
32 |
Execution timed out |
2112 ms |
363992 KB |
Time limit exceeded |