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

32895번 - Glued Grid 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 2048 MB409735.000%

문제

A sliding puzzle consists of square tiles on a rectangular grid. Exactly one of the grid positions is empty, so that you can move the tile above, below, to its left, or to its right into the empty square and back.

Each tile is labelled with a unique number, as shown in Figure G.1. To solve a sliding puzzle, you need to find a sequence of moves that puts the tile numbers in ascending order, from left to right and top to bottom, such that the empty square ends up at the bottom right position in the grid, as shown in Figure G.2. Such a sequence of moves does not exist for all sliding puzzles.

Figure G.1: Example of a 3-by-4 sliding puzzle, corresponding to Sample Input 1. Figure G.2: The sliding puzzle of Figure G.1 after solving. Figure G.3: Example of a sliding puzzle with glued tiles, covered in green goo. This example is possible to solve, corresponding to Sample Input 3.

While cleaning out your garage, you grapple with the garage goblins over a glowing box full of goodies. They offer a gamble: the box is yours if you can solve all their sliding puzzles. You accept to give it a go, only to find out that the garage goblins have glued some tiles in place! The glued tiles no longer move, as shown in Figure G.3.

However, all sliding puzzles share the following properties:

  • The empty square is at the bottom right position.
  • Every glued tile is in its correct position.
  • For each tile that can move, there is a sequence of moves that leaves the empty square in its position instead.
  • From any glued tile, there is a path to the border of the sliding puzzle across glued tiles only, when stepping to the tile above, below, to the left, or to the right at each step. That is, no glued tiles are encircled by tiles that can move.

Determine whether it is possible to solve a given sliding puzzle.

입력

The input consists of:

  • One line with two integers $h$ and $w$ (1ドル \le h,w \le 500$), the height and width of the sliding puzzle's grid.
  • $h$ lines with $w$ characters, each character being either '.' or '#'. The bottom right character, at the position of the empty square,
  • is '.'. Otherwise, '.' denotes a tile that can move, and '#' denotes a glued tile.
  • $h$ lines with $w$ integers $a_{i,j}$ (1ドル \le i \le h,ドル 1ドル \le j \le w,ドル 0ドル \le a_{i,j} \le h \cdot w - 1$). The bottom right integer is $a_{h,w} = 0,ドル representing the empty square. Otherwise, $a_{i,j}$ is the label on the tile at position $(i,j)$.

The set of all $a_{i,j}$ (1ドル \le i \le h, 1 \le j \le w$) contains each of the numbers 0,ドル 1, \dots, h \cdot w - 1$ once.

출력

Output possible if the sliding puzzle can be solved, or impossible if not.

제한

예제 입력 1

3 4
....
....
....
10 8 2 3
6 7 5 9
11 1 4 0

예제 출력 1

possible

예제 입력 2

2 4
....
....
2 1 3 4
5 6 7 0

예제 출력 2

impossible

예제 입력 3

3 4
..#.
....
#...
5 1 3 4
2 6 7 8
9 10 11 0

예제 출력 3

possible

예제 입력 4

3 4
..#.
....
#...
7 1 3 4
5 6 2 8
9 10 11 0

예제 출력 4

impossible

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2024 G번

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

출처

대학교 대회

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

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