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

30940번 - Pingvin 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB139773444.737%

문제

Zrakoplović the penguin wants to learn how to fly!

The space in which he will learn to fly can be imagined as a cube of dimensions $n \times n \times n,ドル divided into $n^3$ unit cubes. Each unit cube can be described with three coordinates $(x, y, z),ドル where $x,ドル $y$ and $z$ are integers between 1ドル$ and $n$. The coordinate $x$ denotes the distance from the left edge of the space, the coordinate $y$ denotes the distance from the front edge of the space, and the coordinate $z$ denotes the height.

Some of these unit cubes contain clouds, and some do not.

Zrakoplović is afraid of clouds, so he will learn to fly only where there are no clouds. He initially finds himself at a position $(x_s, y_s, z_s),ドル such that $z_s = 1$ (i.e. at height 1ドル$), and wants to get to position $(x_e, y_e, z_e)$.

At the moment, he is perfecting the skill of flying in directions that are parallel to one of the axes of space (i.e. in the direction of the $x$-axis, $y$-axis or $z$-axis), and in one wing flap he can cross at most one unit cube.

Before he decides to fly, Zrakoplović wants to know how many wing flaps he needs to get to the desired position. While he is preparing for the flight, help him answer that question.

입력

The first line contains an integer $n$ (1ドル ≤ n ≤ 100$), the dimension of the space in which Zrakoplović learns to fly.

The second line contains three integers $x_s,ドル $y_s$ and $z_s$ (1ドル ≤ x_s, y_s ≤ n,ドル $z_s = 1$), the start position of Zrakoplović.

The third line contains three integers $x_e,ドル $y_e$ and $z_e$ (1ドル ≤ x_e, y_e, z_e ≤ n$), the end position of Zrakoplović.

This is followed by $n$ binary matrices of dimensions $n \times n$ that describe the space, where the $i$-th matrix describes the space at height $i$. The upper-left corner has the coordinates $(1, 1, i)$. The row and column of the matrix correspond to the $x$ and $y$ coordinates, respectively.

'0' denotes a unit cube in which there are no clouds, and '1' denotes a unit cube in which there are clouds.

The start and end position of Zrakoplović will not be a cloud.

출력

In the first and only line, print the smallest number of wing flaps that Zrakoplović must make to reach the desired position. If Zrakoplović cannot reach the desired position, print '-1'.

제한

서브태스크

번호배점제한
17

$n = 2$

216

There are no clouds.

322

All positions with $z$-coordinate greater than 1ドル$ will be clouds.

425

No additional constraints.

예제 입력 1

2
1 1 1
1 1 2
00
10
01
00

예제 출력 1

1

예제 입력 2

3
2 3 1
1 1 1
000
010
000
111
111
111
111
111
111

예제 출력 2

3

예제 입력 3

3
2 1 1
3 2 2
000
010
110
010
001
001
101
110
000

예제 출력 3

3

힌트

Clarification of the first example:

Zrakoplović can reach the desired position in one wing flap by moving in the direction of the $z$-axis for one unit cube.

Clarification of the third example: Zrakoplović can reach the desired position in three wing flaps by first moving to position $(2, 1, 2),ドル then to $(2, 2, 2)$ and finally to $(3, 2, 2)$.

출처

Contest > Croatian Open Competition in Informatics > COCI 2023/2024 > Contest #2 2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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