아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Checkpoint

면접 대비

시간 제한1초메모리 제한1024 MB

요약
격자 미로에서 S에서 E까지 이동하되 번호가 붙은 체크포인트를 오름차순으로 모두 들르는 최단 경로의 길이를 구해 출력한다.
난이도

보통10점 중 6점

유형
BFS, 그래프, 최단 경로, 구현
정답자
아직 제출이 없습니다

문제

A drone is being tested by finding the shortest path through a maze, reaching every checkpoint on the way in order. Your task is to write a program that finds the shortest path from the start, through every checkpoint in order, and then to the exit, then prints the length of that path.

입력

The first line will contain a single integer n that indicates the number of data sets that follow. Each data set will start with three integers r, c, and d representing the number of rows and columns of the maze and the number of checkpoints, respectively. The next r lines will make up the maze, with S being the starting point, E being the end point, the numbers 1-9 being checkpoints, # being a wall, and . being an open space. S and E also count as open spaces.

출력

The output will be the length of the shortest path from the start, through every checkpoint in order, and to the exit. There will be n lines of output with no trailing whitespace.

예제1

  1. 예제 1

    입력
    2
    5 8 2
    S....1..
    .######.
    ..2.#...
    .######.
    ......E.
    1 11 2
    S...1...E.2
    
    예상 출력
    24
    12