Logo
(追記) (追記ここまで)

6969번 - Mountain Passage 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB129981.818%

문제

Alp the mountain climber is on the northwest corner of a square area of a mountainous terrain and wishes to find a passage to the opposite (southeast) corner. Alp is currently at an elevation at which oxygen is not needed, but at any higher elevation oxygen is required. Oxygen, when required, is used at the rate of one unit per horizontal step.

The northwest corner of the terrain is at position $(1, 1)$ and the southeast corner is at position $(n, n),ドル where $n$ is a positive integer read from the input file. The elevation of each point $(x, y),ドル $(1 \le x, y \le n),ドル is an integer read from the input; each elevation occupies a single line in the input file.

Alp moves in a series of horizontal steps, where each step moves Alp a unit north, a unit south, a unit east, or a unit west. Alp must remain in the square region and cannot climb or descend more than 2 units of elevation in a single step. If the elevation at either the beginning or the end of the step requires oxygen, a unit of oxygen is consumed by Alp during the step.

입력

The first line of input is a positive integer indicating the number of trips that Alp must make. For each trip, there is a number of input lines. The first line for each trip contains an integer $n \le 25,ドル indicating the size of the square area of terrain. The next $n^2$ lines each contain a single integer indicating the elevation of a particular point of terrain. The elevations are given for the points in the following order: $(1, 1), (1, 2), (1, 3), \dots (1, n), (2, 1), (2, 2), \dots (n, 1), (n, 2), \dots (n, n)$.

출력

For each trip, if a passage exists, the output is a single line containing an integer indicating the number of units of oxygen consumed. If a passage does not exist, the output is a single line containing the message CANNOT MAKE THE TRIP. Output lines for the trips should be separated by a single blank line.

제한

예제 입력 1

2
5
5
4
3
2
1
7
5
6
6
6
8
8
8
9
6
9
6
9
9
6
4
5
4
5
3
2
4
9
9
4

예제 출력 1

5
CANNOT MAKE THE TRIP

힌트

출처

Olympiad > Canadian Computing Competition & Olympiad > 1998 > CCC 1998 5번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /