Treasures in a map (1) X68356


Statement
 

pdf   zip

Write a program that, given a map with treasures and obstacles, indicates if is possible or not to arrive to any treasure from a given initial position. The allowed movements are horizontal or vertical, but not diagonal. If it is necessary, passing over the treasures is allowed.

Input

Input starts with the number of rows nn and the number of columns mm of the map. nn rows follow with mm characters each one. A dot indicates an empty position, a ’X’ indicates an obstacle, and a ’t’ indicates a treasure. Finally, a pair of numbers rr and cc indicates the initial row and column (both of them starting with 1) where your program must start to look for the treasures. You can suppose that n>0n > 0, that m>0m > 0, that rr will be between 1 and nn, that cc will be between 1 and mm, and that the initial position will be always in an empty position.

Output

Your program must print "1" or "0" depending on if it possible or not to arrive to any treasure.

Observation

The simplest way to solve this exercise does not use any queue.

Public test cases
  • Input

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

    Output

    1
    
  • 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

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