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

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

Field Navigation

면접 대비

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

요약
시작점, 모자, 세 종류의 장애물이 있는 격자에서 모자에 도달할 수 있도록 필요한 도구 종류의 최소 개수를 구한다.
난이도

보통10점 중 5점

유형
BFS, 그래프, 비트 연산, 완전 탐색
정답자
아직 제출이 없습니다

문제

Your field has become quite cluttered, and you just realized you left your best hat out in the middle of the pasture. You have to go retrieve it before it stays out any longer than it already has, but you’re also lazy. And there are many obstacles in the way. You have a sickle to cut tall grass, and an axe to chop up any wood in the way, as well as a hammer to destroy rocks you can’t get through, but you don’t want to have to carry them all. Given the location of your hat and the layout of the field and all the obstacles, determine the minimum number of tools you’ll have to bring to reach your prized hat.

입력

The first line will contain a single integer n that indicates the number of data sets that follow. Each data set will start with a single integer s denoting the side length of your square field. The next s lines will consist of a map of your field, with ‘.’ denoting open space, ‘X’ denoting your hat, ‘S’ denoting your starting position leaving your house, ‘R’ denoting a rock, ‘B’ denoting a branch, and ‘G’ denoting tall grass. You can only move up, down, left, and right. No diagonals.

출력

For each test case, output the minimum number of tools needed to retrieve your hat.

예제1

  1. 예제 1

    입력
    3
    5
    S....
    GGGG.
    .....
    .RRRR
    ....X
    7
    BRBRGGG
    RGGGGRG
    BGBBRRG
    RGGGGRG
    BBRBGBG
    GGRBGRG
    SGGGGRX
    4
    GGGX
    RRRG
    BBRG
    SBRG
    
    예상 출력
    0
    1
    3