-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1192.cpp
More file actions
61 lines (59 loc) · 1.58 KB
/
1192.cpp
File metadata and controls
61 lines (59 loc) · 1.58 KB
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
55
56
57
58
59
60
61
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n, m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cin >> a[i][j];
}
}
int ans = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if (a[i][j] == '.')
{
ans++;
a[i][j] = '#';
vector<pair<int, int>> q;
q.push_back({i, j});
while (!q.empty())
{
int x = q.back().first;
int y = q.back().second;
q.pop_back();
if (x + 1 < n && a[x + 1][y] == '.')
{
q.push_back({x + 1, y});
a[x + 1][y] = '#';
}
if (x - 1 >= 0 && a[x - 1][y] == '.')
{
q.push_back({x - 1, y});
a[x - 1][y] = '#';
}
if (y + 1 < m && a[x][y + 1] == '.')
{
q.push_back({x, y + 1});
a[x][y + 1] = '#';
}
if (y - 1 >= 0 && a[x][y - 1] == '.')
{
q.push_back({x, y - 1});
a[x][y - 1] = '#';
}
}
}
}
}
cout << ans << endl;
return 0;
}