Under construction

Still being built. Things may change

Deadly School Route

Interview

Time limit1sMemory limit1024 MB

Summary
Given a grid of red and gray blocks, the task checks whether a path of same-colored blocks with Manhattan jumps up to X connects the top-left and bottom-right corners.
Level

Easy3 of 10

Topics
Graph, BFS
Solved
No attempts yet

Problem

Jihun moves along his school route by stepping only on paving blocks of the same color. He dies if he steps on a block of a different color.

The route can be represented as an N×MN \times M matrix, and each element of the matrix is one paving block. Jihun starts at row 1, column 1 and must arrive at row NN, column MM.

While moving along a route made of red or gray blocks, Jihun must step only on blocks with the same color as the block he is currently standing on. His jump power is XX, so he can move only between blocks whose Manhattan distance is at most XX. Determine whether Jihun can reach school alive.

Input

The first line contains the number of rows NN (2≤N≤100)(2 \le N\le 100). The second line contains the number of columns MM (2≤M≤100)(2 \le M\le 100). The next NN lines each contain MM integers separated by spaces, where the ii-th of these lines gives the colors of the blocks in row ii from left to right. 00 means a red block and 11 means a gray block. The last line contains Jihun's jump power XX (1≤X≤10)(1 \le X \le 10).

Output

Print ALIVE if Jihun can complete the trip alive, otherwise print DEAD.

Hint

The Manhattan distance between the block at row x_1x\_1, column y_1y\_1 and the block at row x_2x\_2, column y_2y\_2 is defined as ∣x_1−x_2∣+∣y_1−y_2∣\lvert x\_1 - x\_2 \rvert + \lvert y\_1 - y\_2 \rvert.

Examples2

  1. Example 1

    Input
    2
    3
    0 0 0
    0 0 0
    1
    
    Expected output
    ALIVE
    
  2. Example 2

    Input
    2
    2
    0 0
    0 1
    5
    
    Expected output
    DEAD