407224: GYM102697 195 Dungeon

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

195. Dungeontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output
This problem is worth 50 points.

Unfortunately, you find yourself trapped in a dungeon, which can be represented as a 2D grid. The dungeon contains some impassable walls, represented by X characters, and empty space, represented as single dots (".").

You start in the top left corner. You want to figure out how many cells are accessible from your starting space. You can move up, down, right, and left any number of times, but you cannot move diagonally, and you cannot move through walls. You also can't go off the board.

Input

The first line of input consists of a single positive integer $$$n$$$: the number of rows and columns of the dungeon (the dungeon is always square).

The next $$$n$$$ lines each contain $$$n$$$ characters: the grid representation of the dungeon. If a character is an "X", it represents an impassable wall, and if a character is a single dot, it represents empty space.

Output

Output a single positive integer $$$k$$$: the number of spaces in the dungeon accessible from your starting space, according to the rules above.

ExamplesInput
5
...X.
..X..
....X
..XXX
.X...
Output
15
Input
5
..X..
.XX..
X....
.....
.....
Output
3

加入题单

上一题 下一题 算法标签: