문제출처 : https://www.acmicpc.net/problem/3184
import sys
from collections import deque
input = sys.stdin.readline
y,x = map(int,input().split())
table = [list(input()[:-1]) for i in range(y)]
check = [[False]*x for i in range(y)]
dx=[1,-1,0,0]
dy=[0,0,1,-1]
answer =[0,0]
animals =[] #[양 수(o), 늑대 수(v)] 가 들어갈 리스트
for _y in range(y):
for _x in range(x):
result = [0,0]
q = deque()
if table[_y][_x] == "o" and check[_y][_x] == False:
check[_y][_x] = True
result[0] += 1
q.append([_y,_x])
elif table[_y][_x] == "v" and check[_y][_x] == False:
check[_y][_x] = True
result[1] += 1
q.append([_y,_x])
while q:
location = q.popleft()
for i in range(4):
b = location[0] + dy[i] if 0<= location[0] + dy[i] < y else location[0]
a = location[1] + dx[i] if 0 <= location[1] + dx[i] < x else location[1]
if table[b][a] == "o" and check[b][a] == False:
check[b][a] = True
result[0] += 1
q.append([b,a])
elif table[b][a] == "v" and check[b][a] == False:
check[b][a] = True
result[1] += 1
q.append([b,a])
elif table[b][a] == "." and check[b][a] == False:
check[b][a] = True
q.append([b,a])
if sum(result) > 0:
animals.append(result)
for i in animals:
if i[0] > i[1]:
answer[0] += i[0]
else:
answer[1] += i[1]
print(*answer)