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

22303번 - Chuck's Challenge 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB1000.000%

문제

Chuck's Challenge is a game in which a player navigates a maze consisting of various tiles in a grid. The player can encounter doors that may be unlocked using keys they acquire along the way. You must write a program to determine the minimum number of doors that must be opened to reach the exit of the maze.

Key

Tile Meaning Passable
> Entrance Yes
< Exit Yes
a-z Key Yes
A-Z Door See rules
. Ground Yes
+ Wall No
Unstable floor See rules

Rules

  • Tiles that are diagonal to each other are not considered to be adjacent (only up, down, left, and right).
  • The player begins the maze visiting the entrance tile.
  • The player may only visit passable tiles that are adjacent to the tile the player is currently visiting.
  • Doors are considered impassable until a tile with a matching key ('A' matches 'a', 'B' matches 'b', etc.) has been visited.
  • At first, unstable floors are considered passable; however, if the player leaves an unstable floor and visits any other type of tile, it becomes impassable.
  • When an unstable floor tile becomes impassable, all adjacent unstable floor tiles become impassable.
  • The external edge of the maze is an impassable wall.

입력

The first line of input will contain the number of test cases, T (1 ≤ T ≤ 50). Each test case will begin with a line containing two integers R C (4 ≤ R, C ≤ 50). Following that will be a maze with R rows and C columns. Only the characters in the key will be present in the maze.

출력

Each test case will have a single line of output. Print the minimum number of doors that must be opened to reach the exit or print "Impossible" if the exit cannot be reached.

제한

예제 입력 1

2
8 15
+++++++++++++++
+>............+
+...a...+~+~+B+
+~+++++++~+~+.+
+~++..b..C+~+.+
+~++A++++++~+.+
+....~~~~~~c+<+
+++++++++++++++
8 6
++++++
+>.A<+
+.++++
+.+.a+
+~~..+
+~~..+
+~~..+
++++++

예제 출력 1

2
Impossible

힌트

출처

ICPC > Regionals > North America > South Central USA Regional > 2014 South Central USA Regional Programming Contest 7번

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

출처

대학교 대회

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

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