printРабочее место участника

printЗадачи

589. Go Scoring

Ограничения: время – 1s/2s, память – 32MiB Ввод: input.txt или стандартный ввод Вывод: output.txt или стандартный вывод copy
Послать решение Blockly Посылки Темы Где Обсудить (0)

Go is played on a board with a 19x19 grid, by two players called Black and White. Starting with an empty board, the players alternate turns placing stones of own color on an unoccupied intersection.
At the end of game players count their scoring. It is taked plenty of time because the number of stones on board can be more than 300. Several variants of go exist and ones use different tricks to simplify counting of scores.
You should write program that count scores in a moment by following rule:
A player's score is the number of stones of her color, plus the number of empty intersections that reach only her color. A empty intersection `P` is said to reach color `C`, if there is a path of adjacent (vertically or horizontally) unoccupied intersections from `P` to a intersection with stone of color `C`.
Input contains 19 lines. Each line contains 19 characters. Character 'B' represents black stone, 'W' – white stone, '.' – unoccupied intersection.
First line of output must contain two integers separated by space – scores of Black and White players.

Sample Input

..B................
..B................
BB.................
...................
...................
...................
...................
...................
...................
...................
...................
...................
...................
...................
...................
......W............
.....W.W...........
......W............
...................

Sample Output

8 5
loading