ÀÂÒ
Language:

Remote Training on Programming

Problems On-line status Contests FAQ
For authors:
Register  ||  Login
 
Hello, Guest! Login or register.

890. Maze

Time Limit: 1 seconds
Memory Limit:32768KB
Points:10
View Problem Statistics Submit Problem added Administrator

Consider a maze of size N by M. Each cell of the maze may be either free, or occupied by a wall. The maze is surrounded by a wall, which has two free cells, entry and exit. The entry is always in the left border of the maze, while the exit is in the right. It is allowed to move in four directions: up, down, left, right. Diagonal moves are forbidden. There is always a path between the entry and the exit.

Such a maze may have several possible paths between the entry and the exit. However, there are cells that will be visited in any case.

Write a program to calculate the number of cells belonging to each path from the entry to the exit.

Limitations

3 ≤ N, M ≤ 999

Input

The first line contains two integer numbers N and M, the dimensions of the maze. The following N lines of M characters describe the maze. Character "#" denotes a wall, and character '.' denotes a free cell.

Output

The output file must contain a single integer – the number of cells belonging to each path from the entry to the exit.

Sample

Standard input

Standard output

7 7
#######
....#.#
#.#.###
#.....#
###.#.#
#.#....
#######

5

 


View Problem Statistics Submit Author/source:
Sorted Problems / Graphs /
63. Even graph 890. 9. Net 292. One-way Racing 246. Path in Labyrinth
Problems from Contests / ACM Contests / Rybinsk-2010 /
889. D - Bubble 890. 891. F - Tree packing 892. G - Solar eclipse 893. H - Green wave
We can all benefit by doing occasional "toy" programs, when artificial restrictions are set up, so that we are forced to push our abilities to the limit. The art of tackling miniproblems with all our energy will sharpen our talents for the real problems. Donald E. Knuth.
time generating 0.047 sec.
© Copyright VSTU, AVT, Nosov D.A.