-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountingrooms.cpp
54 lines (41 loc) · 1012 Bytes
/
countingrooms.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<ll, ll>;
using vi = vector<ll>;
ll n, m;
vector<vector<bool>> a;
vector<vector<bool>> visited;
void f_fill(ll x, ll y) {
if (x < 0 || x >= n || y < 0 || y >= m) return;
if (visited[x][y]) return;
if (a[x][y]) return;
visited[x][y] = true;
f_fill(x + 1, y);
f_fill(x - 1, y);
f_fill(x, y + 1);
f_fill(x, y - 1);
}
int main() {
cin >> n >> m;
a = vector<vector<bool>>(n, vector<bool>(m, 0));
visited = vector<vector<bool>>(n, vector<bool>(m, 0));
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
char c;
cin >> c;
if (c == '#') a[i][j] = true;
}
}
int sum = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if (!visited[i][j] && !a[i][j]) {
sum++;
f_fill(i, j);
}
}
}
cout << sum << endl;
return 0;
}