#954
Gold III
VUK
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Filip Barl Vjekoslav the Wolf is running away from a bunch of blood hungry hunters. The hunters are smart and hide behind trees. Vjekoslav knows this, but doesn't know which trees. He would like to run to his comfortable, civilized cottage (as opposed to the hunters quite uncivilized den, yes I am rooting for the Wolf here) staying as far away as possible from any trees. The forest can be represented as a N by M gird. Let us mark empty meadow patches with '.', patches with a tree in the middle with '+', Vjekoslav's current position with 'V' and the position of his cottage with 'J'. Vjekoslav can run from his current patch to any other patch north, east, south or west from him, even if it contains a tree. If Vjekoslav is standing in R-th row and C-th column on the grid and there is a tree in the A-th row and B-th column then the distance between Vjekoslav and that tree is: |R-A| + |C-B| Help Vjekoslav find the best route to his cottage. The best route is any route that maximizes the minimal distance between Vjekoslav and all trees at any given moment. Note that Vjekoslav's cottage doesn't occupy the entire patch so that patch must also be included in the route.

입력

The first line of input contains integers N and M (1 ≤ N, M ≤ 500), grid dimensions. The next N lines contain M characters each: '.', '+', 'V', 'J'. Input will contain exactly one character 'V' and 'J' and at least one character '+'.

출력

Output a single integer, the minimal distance from a tree in the optimal route. Author: Filip Barl

예제 입력 1

4 4
+...
....
....
V..J

예제 출력 1

3

예제 입력 2

4 5
.....
.+++.
.+.+.
V+.J+

예제 출력 2

0

예제 입력 3

6 6
.++...
J.+.+.
.+.+..
....+.
+++.+.
...+.V

예제 출력 3

0
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Gold III1명 투표· 약 1개월 전
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.