#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 {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
302 ms |
10232 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
204 KB |
Output isn't correct |
4 |
Correct |
44 ms |
6260 KB |
Output is correct |
5 |
Incorrect |
68 ms |
804 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 |
Correct |
3 ms |
460 KB |
Output is correct |
9 |
Incorrect |
4 ms |
332 KB |
Output isn't correct |
10 |
Incorrect |
66 ms |
620 KB |
Output isn't correct |
11 |
Correct |
10 ms |
2124 KB |
Output is correct |
12 |
Correct |
86 ms |
3372 KB |
Output is correct |
13 |
Incorrect |
67 ms |
752 KB |
Output isn't correct |
14 |
Incorrect |
67 ms |
716 KB |
Output isn't correct |
15 |
Correct |
623 ms |
2352 KB |
Output is correct |
16 |
Correct |
305 ms |
10232 KB |
Output is correct |
17 |
Incorrect |
492 ms |
2936 KB |
Output isn't correct |
18 |
Correct |
37 ms |
6092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1062 ms |
1176 KB |
Output isn't correct |
2 |
Execution timed out |
2065 ms |
5268 KB |
Time limit exceeded |
3 |
Execution timed out |
2029 ms |
34672 KB |
Time limit exceeded |
4 |
Execution timed out |
2071 ms |
11676 KB |
Time limit exceeded |
5 |
Execution timed out |
2060 ms |
19392 KB |
Time limit exceeded |
6 |
Execution timed out |
2044 ms |
312556 KB |
Time limit exceeded |
7 |
Incorrect |
1200 ms |
1240 KB |
Output isn't correct |
8 |
Incorrect |
1079 ms |
1220 KB |
Output isn't correct |
9 |
Incorrect |
157 ms |
920 KB |
Output isn't correct |
10 |
Incorrect |
271 ms |
520 KB |
Output isn't correct |
11 |
Incorrect |
725 ms |
1316 KB |
Output isn't correct |
12 |
Incorrect |
101 ms |
728 KB |
Output isn't correct |
13 |
Execution timed out |
2069 ms |
5272 KB |
Time limit exceeded |
14 |
Execution timed out |
2073 ms |
3692 KB |
Time limit exceeded |
15 |
Execution timed out |
2070 ms |
2596 KB |
Time limit exceeded |
16 |
Execution timed out |
2072 ms |
3324 KB |
Time limit exceeded |
17 |
Execution timed out |
2071 ms |
9964 KB |
Time limit exceeded |
18 |
Execution timed out |
2060 ms |
8872 KB |
Time limit exceeded |
19 |
Execution timed out |
2067 ms |
11632 KB |
Time limit exceeded |
20 |
Execution timed out |
2078 ms |
7992 KB |
Time limit exceeded |
21 |
Execution timed out |
2082 ms |
20252 KB |
Time limit exceeded |
22 |
Execution timed out |
2090 ms |
19392 KB |
Time limit exceeded |
23 |
Execution timed out |
2092 ms |
17732 KB |
Time limit exceeded |
24 |
Execution timed out |
2079 ms |
19628 KB |
Time limit exceeded |
25 |
Execution timed out |
2029 ms |
34152 KB |
Time limit exceeded |
26 |
Correct |
1695 ms |
601388 KB |
Output is correct |
27 |
Execution timed out |
2091 ms |
225344 KB |
Time limit exceeded |
28 |
Execution timed out |
2094 ms |
312408 KB |
Time limit exceeded |
29 |
Execution timed out |
2093 ms |
275388 KB |
Time limit exceeded |
30 |
Execution timed out |
2099 ms |
253828 KB |
Time limit exceeded |
31 |
Execution timed out |
2083 ms |
75424 KB |
Time limit exceeded |
32 |
Execution timed out |
2078 ms |
379720 KB |
Time limit exceeded |