Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. 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
|
Для отправки решений необходимо выполнить вход.
|