/**
* author: mahfuzz
* created: 02.07.2021
**/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define all(p) p.begin(),p.end()
typedef long long ll;
const int maxn = 200;
int mat[maxn][maxn];
int x[] = {0, 0, -1, 1};
int y[] = {-1, 1, 0, 0};
int main(int argc, char* argv[]){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int n, m; cin >> n >> m;
char grid[n + 1][m + 1];
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> grid[i][j];
}
}
int cnt = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(grid[i][j] == '*'){
bool flag = false;
for(int k = 0; k < 4 && !flag; k++){
int xx = i + x[k];
int yy = j + y[k];
if(mat[xx][yy] != 0){
mat[i][j] = mat[xx][yy];
flag = true;
}
}
if(!flag){
++cnt;
mat[i][j] = cnt;
}
}
}
}
cout << cnt << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
324 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |