#include<bits/stdc++.h>
using namespace std;
int N, M;
char grid[101][101];
int dx[ ] = {-1, 1, 0, 0}, dy[ ] = {0, 0, 1, -1};
bool vis[101][101];
bool OK(int& x, int& y){
return (x >= 0 && y >= 0 && x < N && y < M);
}
inline void Dfs(int& x, int& y){
vis[x][y] = 1;
for (register int i = 0; i < 4; ++i){
int tx = x + dx[i], ty = y + dy[i];
if(!OK(tx, ty)) continue;
if(vis[tx][ty]) continue;
Dfs(tx, ty);
}
return;
}
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> N >> M;
for (register int i = 0; i < N; ++i){
for (register int j = 0; j < M; ++j){
cin >> grid[i][j];
if(grid[i][j] ^ '*') vis[i][j] = 1;
}
}
int ans(0);
for (register int i = 0; i < N; ++i){
for (register int j = 0; j < M; ++j){
if(grid[i][j] == '*' && !vis[i][j]){
Dfs(i, j); ++ans;
}
}
}
cout << ans << '\n';
return 0;
}
Compilation message
emacs.cpp: In function 'void Dfs(int&, int&)':
emacs.cpp:18:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
18 | for (register int i = 0; i < 4; ++i){
| ^
emacs.cpp: In function 'int main()':
emacs.cpp:30:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
30 | for (register int i = 0; i < N; ++i){
| ^
emacs.cpp:31:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
31 | for (register int j = 0; j < M; ++j){
| ^
emacs.cpp:37:20: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
37 | for (register int i = 0; i < N; ++i){
| ^
emacs.cpp:38:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
38 | for (register int j = 0; j < M; ++j){
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |