HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Functions > problem:


50982 - A thief in labyrinth

Guest
• Review clarifications (1)

Volume problems

• 50296 - Total Discount Rate
• 50935 - Max Discount
• 50851 - Repeated Numbers
• 50838 - Balanced Numbers
• 50724 - Number of Circles
• 50916 - Ascending Numbers
• 50926 - School Mail Merge
• 50917 - Descending Numbers
• 50982 - A thief in labyrinth
• 50980 - The smallest rectangle
• 50932 - Shifting rows and columns
• 50933 - Sum of the Biggest Neighbors
• 50834 - The train which leaves the f...
• 51003 - Double Prime
• 50435 - City Electric Bills
• 50527 - Sum of LCMs
• 50353 - Cube of the Largest number

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

A thief in labyrinth

Question: The police is running after a thief who is trying to run out of the building. Because, he wants to go out of high building, he goes only down, left, or right to the rooms which he did not visit before. And, he chooses always the room with the smaller value among the three adjacent rooms. Clever detective Jones knows this strategy and waiting outside of the building on his escape point at the ground floor. Write a program that finds the exit point of the thief.

Input specification: You will be given two integers in the beginning: the size of building (n) and starting room of the thief (x). In the following n lines, you will be given n integers which are between -10,000 and 10,000 where 1 ≤ x ≤ n ≤ 100

Output specification: Show the room number that the thief leaves the building on the ground floor. Note:If the three adjacent rooms have the same min values, follow the order: down, left and right.

Sample Input
6 6
10 18 4 14 0 8
4 20 18 4 17 2
7 16 19 13 20 10
11 7 0 7 11 10
11 2 8 13 8 20
5 6 6 11 20 5
Sample Output
2



Для отправки решений необходимо выполнить вход.

www.contester.ru