This page is still under construction.

Parts of this page are still being built. What you see may change.

Arrow Maze (Normal)

Interview

Time limit3sMemory limit512 MB

Summary
Given a grid of arrows and K sets of one clockwise and one counterclockwise rotation scroll, decide whether some sequence of moves and rotations reaches the bottom-right cell from the top-left.
Level

Medium7 of 10

Topics
Graph, BFS, Shortest path, Implementation
Solved
No attempts yet

Problem

Apart from the input constraints, there is no difference between the difficulty versions of this problem.

After 25 years of lonely training, Mingyu finally became a wizard. As a wizard, Mingyu had a dream: to build a magically wonderful theme park! As the theme park's first attraction, Mingyu unveiled the "Arrow Maze."

The Arrow Maze differs from an ordinary maze in many ways. It consists of R×C rooms. Every room is walled off on all four sides so that no two rooms are connected, and each room is decorated with dazzling sights of a completely different theme.

Map of the Arrow Maze

If every room is walled off on all four sides, how can one move between rooms? Mingyu drew a special magic circle in each room and designed it so that a person can teleport one cell in the direction of the arrow drawn on that magic circle! The outermost wall of the maze is surrounded by magma, so you cannot cross the outermost wall surrounding the maze and escape the maze itself.

Customers using the Arrow Maze start at the entrance in room (1,1), the top-left room, experience various rooms, and must finish the maze at the exit in room (R,C), the bottom-right room. If they fail to do so, they will wander the Arrow Maze forever! Naturally, depending on the arrow directions of the magic circles Mingyu originally drew, it may be impossible to reach the exit.

So that people can enjoy the Arrow Maze safely, Mingyu decided to sell special scrolls at the maze's entrance. There are two kinds of scrolls: the 'L scroll,' which rotates an arrow counterclockwise, and the 'R scroll,' which rotates an arrow clockwise. Using such a scroll rotates the arrow in that room by 90 degrees. You can use several scrolls in a row on a single magic circle to make it rotate 180 or 270 degrees. To maximize profit, Mingyu sells only sets, each containing one L scroll and one R scroll.

Customers using the Arrow Maze receive the map only after entering the maze, so to avoid wandering the Arrow Maze forever, they had no choice but to buy large numbers of scroll sets. Mingyu's friend Junseo, a frequent visitor of the Arrow Maze, was suffering this same inconvenience.

Junseo: Hey, at least tell me whether what I have now is enough or not??

Tired of Junseo's complaints, Mingyu decided that, just for Junseo, he would answer the question whether the scroll sets Junseo has are enough to reach the exit exactly once with "Yes" or "No". Answering accurately is very difficult for Mingyu, so he commissioned you to write a program that answers the question in his place.

Input

The first line gives the number of rows R and columns C of the maze and the number of scroll sets Junseo has, K.

From the second line, R lines give the map of the Arrow Maze. Each line contains a string of length C consisting only of "UDLR", where U means a magic circle that can move up, D down, L left, and R right.

Output

Print the answer to Junseo's question as "Yes" or "No".

Constraints

1 ≤ R, C ≤ 50

0 ≤ K ≤ 150

Examples2

  1. Example 1

    Input
    3 3 1
    RDR
    URU
    UDR
    
    Expected output
    Yes
    
  2. Example 2

    Input
    10 10 5
    RDDRULURRD
    DRLLLDURUD
    URLDRRLURR
    DRLRLUDRUR
    UUDLRRUURR
    LLDLRRULRR
    DUURUDUULU
    ULLLRLDRUD
    DLRDDLDRDL
    DLLUDLUULD
    
    Expected output
    Yes