HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


50982 - A thief in labyrinth

Guest
• Review clarifications (1)

Section problems

• 50829 - Decode an Image
• 50851 - Repeated Numbers
• 50838 - Balanced Numbers
• 50515 - Lines - Revisited
• 50913 - Manhattan Distance
• 50824 - Sum of Group Maxes
• 50449 - The biggest result
• 50442 - Polynomial Addition
• 50982 - A thief in labyrinth
• 50989 - Rectangles and Points
• 50932 - Shifting rows and columns
• 50497 - Falling Bricks - Revisited
• 50933 - Sum of the Biggest Neighbors
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 50874 - Apartment Building Adminis...
• 51127 - Maze solver

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