-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJ_3184.py
More file actions
44 lines (35 loc) · 802 Bytes
/
BJ_3184.py
File metadata and controls
44 lines (35 loc) · 802 Bytes
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
import sys
limit_number = 150000
sys.setrecursionlimit(limit_number)
dr = [-1,0,1,0]
dc = [0,1,0,-1]
R,C = map(int, input().split())
area1 = [list(input()) for _ in range(R)]
def DFS(r,c):
global ww,ss
if area1[r][c] == 'o':
ss += 1
if area1[r][c] == 'v':
ww += 1
area1[r][c] = '#'
for i in range(4):
nr = r + dr[i]
nc = c + dc[i]
if nr < 0 or nr >= R or nc < 0 or nc >= C:
continue
if area1[nr][nc] == '#':
continue
DFS(nr,nc)
wolf = 0
sheep = 0
for i in range(R):
for j in range(C):
if area1[i][j] != '#':
ww = 0
ss = 0
DFS(i,j)
if ww < ss:
sheep += ss
else:
wolf += ww
print(sheep,wolf)