HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


50982 - A thief in labyrinth

Guest
• Review clarifications (1)

Section problems

• 51125 - Filling an Array 3
• 50824 - Sum of Group Maxes
• 50449 - The biggest result
• 51172 - The biggest Minute
• 51085 - xyx Divisible by k
• 51087 - Are they the same?
• 50442 - Polynomial Addition
• 51015 - Student Scholarships
• 50982 - A thief in labyrinth
• 51091 - Guess the number - 1
• 51008 - Sum of Regional Maxes
• 50989 - Rectangles and Points
• 51020 - Number of nodes removed
• 50932 - Shifting rows and columns
• 51141 - Most valuable stock items
• 51014 - Nine Men's Morris game
• 51019 - Finding the hidden message

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