Treasures in a map (3) P90766


Statement
 

pdf   zip

Write a program that, given a map with treasures and obstacles, computes the number of treasures that can be reached from a given initial position. The allowed movements are horizontal or vertical, but not diagonal. If needed, passing over the treasures is allowed.

Input

Input begins with the number of rows n>0n > 0 and the number of columns m>0m > 0 of the map. Follow nn rows with mm characters each. A dot indicates an empty position, an ‘X’ indicates an obstacle, and a ‘t’ indicates a treasure. Finally, two numbers rr and cc indicate the initial row and column (both of them starting at 1) where we must start looking for treasures. You can assume that rr is between 1 and nn, that cc is between 1 and mm, and that the initial position is always empty.

Output

Print the number of accessible treasures from the initial position.

Public test cases
  • Input

    7 6
    ..t...
    ..XXX.
    ......
    tX..X.
    .X..Xt
    .XX...
    ..t...
    5 3
    

    Output

    4
    
  • Input

    4 10
    ..t...X...
    .....X..t.
    XXXXX.X...
    .......X.t
    4 1
    

    Output

    0
    
  • Input

    5 7
    .......
    .XXXXXt
    .X...Xt
    .X.X.XX
    ...X.Xt
    5 5
    

    Output

    2
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Python