RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
COCI00190

Poštar

Platinum IV 플래티넘 IV
난이도
4s
시간 제한
32MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Mirko has got a mailman job in a small town in the hills. The town can be represented by an \(N \times N\) matrix. Each field contains one of the following, exclusively: a house denoted by K, the post office denoted by P, or a pasture denoted by .. Additionally, each field is assigned an altitude.

Every morning, Mirko delivers mail to all houses in the town. He starts at the field denoted by P, which represents the single post office in the town. Mirko is allowed to move horizontally, vertically and diagonally, to adjacent squares only. Once he delivers the last piece of mail, he must return to the post office.

Let the difference between the heights of the highest and the lowest field Mirko visits while delivering the mail be equal to his tiredness. Help him out and determine the least tiredness possible for Mirko to deliver all the mail.

제약
입력 형식

The first line of input contains an integer \(N\) (\(2 \le N \le 50\)).

The following \(N\) lines represent the fields in the corresponding matrix row. The character P will appear exactly once, while the character K will appear at least once.

The following \(N\) lines each contain \(N\) positive integers, the altitudes of the fields in the corresponding matrix row. Those values are less than \(1\,000\,000\).

출력 형식

In a single line of output print a single integer that represents the minimum possible tiredness.

서브태스크
서브태스크점수설명

Test 1

5점

None

Test 2

5점

None

Test 3

5점

None

Test 4

5점

None

Test 5

5점

None

Test 6

5점

None

Test 7

5점

None

Test 8

5점

None

Test 9

4점

None

Test 10

4점

None

Test 11

4점

None

Test 12

4점

None

Test 13

4점

None

Test 14

4점

None

Test 15

4점

None

Test 16

4점

None

Test 17

4점

None

Test 18

4점

None

Test 19

4점

None

Test 20

4점

None

Test 21

4점

None

Test 22

4점

None

Test 23

4점

None

예제 1
입력
2
P.
.K
2 1
3 2
출력
0
예제 2
입력
3
P..
.KK
...
3 2 4
7 4 2
2 3 1
출력
2
예제 3
입력
3
K.P
...
K.K
3 3 4
9 5 9
8 3 7
출력
5
문제 정보

riseoj 작성

출처 COCI 2010/2011 Contest 7

평가 및 의견

Poštar

개요
출제자 난이도 Platinum IV 플래티넘 IV 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Poštar

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8