-
Notifications
You must be signed in to change notification settings - Fork 0
/
3184.cpp
56 lines (50 loc) · 1.01 KB
/
3184.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
55
56
#include<cstdio>
#include<vector>
using namespace std;
vector<pair<int, int>> p;
char arr[250][250];
int r, c, sc, wc;
int check[250][250];
int dx[4] = { -1, 1, 0, 0 };
int dy[4] = { 0, 0, 1, -1 };
void go(int y, int x) {
check[y][x] = 1;
if (arr[y][x] == 'o') sc++;
else if (arr[y][x] == 'v') wc++;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (0 <= nx && nx < c && 0 <= ny && ny < r && !check[ny][nx] && arr[ny][nx] != '#')
go(ny, nx);
}
}
int main() {
scanf("%d%d", &r, &c);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
scanf(" %c", &arr[i][j]);
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (!check[i][j] && arr[i][j] != '#') {
go(i, j);
p.push_back(pair<int, int>(sc, wc));
sc = 0;
wc = 0;
}
}
}
for (int i = 0; i < p.size(); i++) {
if (p[i].second < p[i].first) {
p[i].second = 0;
sc += p[i].first;
}
else {
p[i].first = 0;
wc += p[i].second;
}
}
printf("%d %d\n", sc, wc);
return 0;
}