Volcano

All submissions for this problem are available.
There is a mountain on Planet Credenz which can be represented by a 2D matrix X of size MxN. Each element of the matrix represents the altitude (height) of the mountain at that location. The mountain has an active volcano which can erupt at any time. The volcano will erupt from a location ( i , j ) which will be specified in the input. The Lava
will then flow from that position to other positions such that
Note that lava will not accumulate unless and until it has a path to flow or it can flow out of the mountain. Also, while accumulating the altitude of the lava at each position where it is present will be equal.
For better understanding of these conditions, consider the flow of lava as the flow
of a real world fluid/liquid.
For example if the mountain matrix is like:
12 12 12 12 8 12 12 10 12
and the lava originates from the position ( 2 , 2 ) with altitude 8 then the lava cannot flow to any neighbor as there is no neighbor which has a lower altitude than or equal to 8. Thus lava will go on accumulating within the boundary and fill up until it reaches an altitude of 10 and then flow out to the location ( 3 , 2 ). This is an edge location and thus the the lava will flow out of the mountain from here.
Your task is to find out which locations of the mountain will be covered with lava.
Output a matrix A of size ( M * N ) where :
Input
First line contains two space separated integers, M and N.
M lines follow, each containing N spaced integers representing the altitude of each part of the mountain.
Next line contains two space separated integers i and j denoting the position of eruption of volcano. (The matrix is 1indexed)
Output
Output M lines, each containing N spaced integers, that is the matrix A.
Constraints
1 ≤ M, N ≤ 200
1 ≤ i ≤ M
1 ≤ j ≤ N
1 ≤ X_{ij} ≤ 10^6
Example
Input: 6 6 6 6 6 6 6 6 6 6 3 3 5 6 6 6 3 3 5 5 6 6 3 4 4 6 5 6 5 6 6 6 5 6 5 6 6 6 2 3 Output: 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 1 1 1 0 0 0 1 0 0 0 0 0 1 0 0 0
Author:  wittyceaser 
Tags  wittyceaser 
Date Added:  28082014 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions